Link to home
Start Free TrialLog in
Avatar of need_help_pls
need_help_pls

asked on

adding a layout manager to JScrollPane

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)


Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

You should set your GridBag layout on a JPanel and add that to the scroll pane.
Avatar of need_help_pls
need_help_pls

ASKER

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??
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??
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.


thanks... makes life easier alright and does the trick!!!

cheers : )