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.ClassCastExcepti on: layout of JScrollPane must be a ScrollPaneLayout
at javax.swing.JScrollPane.se tLayout(JS crollPane. java:404)
at InterpreterGUI.createMemor y(Interpre terGUI.jav a:469)
at InterpreterGUI.createMainP anel(Inter preterGUI. java:183)
at InterpreterGUI.<init>(Inte rpreterGUI .java:28)
at InterpreterMain.main(Inter preterMain .java:19)
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.ClassCastExcepti
at javax.swing.JScrollPane.se
at InterpreterGUI.createMemor
at InterpreterGUI.createMainP
at InterpreterGUI.<init>(Inte
at InterpreterMain.main(Inter
You should set your GridBag layout on a JPanel and add that to the scroll pane.
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??
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
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??
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER
thanks... makes life easier alright and does the trick!!!
cheers : )
cheers : )