LAyout managing in a scrollpane (re-post from 'new to java')

Hi,

I have a JTable, which is sitting in a scrollpane in a JInternalFrame. The scroller works fine, in that scrollbars appear when the frame is made smaller than the table. So its a bit like this...

paramsTable = JTable (etc)...

iframeParams = JInternalFrame();

scroller = JScrollPane();

scroller.add(paramsTable);

scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);

scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

iframeParams.add(scroller);

However, if the frame is made larger than the table, then the table just sits in the extreme top left corner of the frame. What I would like is for it allways to be centred, so presumably I need to have some sort of layout manager in there? If I try to use 'setLayout' on the scrollpane I get an exception (java.lang.ClassCastException: layout of JScrollPane must be a ScrollPaneLayout).

What should I do? Should I somehow be putting the table into JPanel with the right layout manager and then putting that into the scrollpane (but when I just try that the table is invisible..). I need to sort this out as I'm going to be putting other components there eventually so I need to work out how to manage the layout.

Cheers,

Arwel

[1331 byte] By [Arwela] at [2007-11-27 7:40:17]
# 1
Did you consider leaving the scroll pane alone, putting all the stuff into a JPanel instead and adding that JPanel to the scroll pane?
CeciNEstPasUnProgrammeura at 2007-7-12 19:20:47 > top of Java-index,Desktop,Core GUI APIs...