?
Solved

adding a layout manager to JScrollPane

Posted on 2003-02-26
6
Medium Priority
?
1,787 Views
Last Modified: 2012-05-04
is there some specific restriction when adding a layout manager to JScrollPane??

i have used the following, as I am creating a simple component to add to a more complicated GridBag system:

   JScrollPane memoryGroup = new JScrollPane();
  memoryGroup.setLayout(new GridLayout                    (numMemoryLocation+1,1));


but i get the following run-time error: - any idea what I am doing wrong??

Exception in thread "main" java.lang.ClassCastException: layout of JScrollPane must be a ScrollPaneLayout
        at javax.swing.JScrollPane.setLayout(JScrollPane.java:404)
        at InterpreterGUI.createMemory(InterpreterGUI.java:469)
        at InterpreterGUI.createMainPanel(InterpreterGUI.java:183)
        at InterpreterGUI.<init>(InterpreterGUI.java:28)
        at InterpreterMain.main(InterpreterMain.java:19)


0
Comment
Question by:need_help_pls
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 8026824
You should set your GridBag layout on a JPanel and add that to the scroll pane.
0
 

Author Comment

by:need_help_pls
ID: 8026850
i want to be able to layout my Scrollpane using something simple like GridLayout cos im returning this Scrollpanel as a component to be included in another panel which is laid out using gridbag...
is there some reason that I should not be able to set the layout of a scrollpane to gridLayout???  or flowLayout maybe??  or am i just making some stupid error with the above code that i cant spot??
0
 

Author Comment

by:need_help_pls
ID: 8026860
i want to be able to layout my Scrollpane using something simple like GridLayout cos im returning this Scrollpanel as a component to be included in another panel which is laid out using gridbag...
is there some reason that I should not be able to set the layout of a scrollpane to gridLayout???  or flowLayout maybe??  or am i just making some stupid error with the above code that i cant spot??
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 86

Accepted Solution

by:
CEHJ earned 60 total points
ID: 8026899
A JScrollPane is not designed to be used like that. If you want a GridLayout, set a JPanel to that layout and add it the JScrollPane.
0
 

Expert Comment

by:apocalypso79
ID: 8030062
Hi,

You can set the layout of JScrollPane using the ScrollPaneLayout class (or a subclass of it). All the other standard Layouts won't work.

Reading the documentation on the sun site should allow you to set a grid-bag like layout (though it'll be some work)

I'm not sure it's necessary though. Think the JPanel solution might suffice.


0
 

Author Comment

by:need_help_pls
ID: 8040880
thanks... makes life easier alright and does the trick!!!

cheers : )
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question