Resizing a JScrollPane

Hi, I have a JScrollPane that contains a JTable inside. Basically, when a user clicks a button or selects an option, the Table Model changes and the table is populated with a different set of data, of a different size. The scrollpane starts off at a size of 500x255, but sometimes there are only a few rows of data to display, and the rest of the scrollpane shows up (below the table) as grey space. An example would be like this:

http://img205.imageshack.us/img205/4899/grrrlu2.png

I've been trying everything I can think of, and I can't get it to work properly. I've tried this:

if(skillTable.getHeight() <= 255){

scrollPane.setPreferredSize(new Dimension(500,skillTable.getHeight() + 19));

scrollPane.revalidate();

}

else{

scrollPane.setPreferredSize(originalDimensions);

scrollPane.revalidate();

}

and it doesn't update right away... I need to click another option (or the same one) again to get it to resize properly. So basically, if I click the same button twice, the pane resizes. If I click one button, then another, it resizes the pane to what the size should've been when I clicked the previous button. Does nayone have any idea what might be causing this? Thanks in advance!

[1470 byte] By [mistah-javaa] at [2007-10-3 1:38:36]
# 1

I would suggest you keep the scrollpane at a constant height and width, and allow the content to scroll automatically. Couldnt see that picture so not sure about the exact error.

You can let the table scroll by setting the resize mode to AUTO_RESIZE_OFF. About the gray scrollpane background that can be fixed by making it blend with the table row color eg scrollpane.getViewport().setBackground(Color.white)

ICE

icewalker2ga at 2007-7-14 18:36:48 > top of Java-index,Desktop,Core GUI APIs...
# 2
That's a great idea - it worked like a charm! I kept trying to change the background color using scrollPane.setBackground(); before but it didn't work (missed the getViewport()). Thanks a ton! :-)
mistah-javaa at 2007-7-14 18:36:48 > top of Java-index,Desktop,Core GUI APIs...