Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

adding a layout manager to JScrollPane

Posted on 2003-02-26
6
Medium Priority
?
1,890 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
  • 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

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month12 days, 12 hours left to enroll

579 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