set size of JTable inside a JScrollPane

Hi,

I'm inserting a JTable into a JScrollPane which is inserted inside a JPanel. I'd like to set the size of this JScrollPane to be the same as the JPanel, so it will show a blank space between the end of my JTable and the end of my JScrollPane.

I've tryed something like:

table.setPreferredScrollableViewportSize(panel.getSize());

but is not working as I wanted.

Does anybody knows how can I do that?

[441 byte] By [Valerianoa] at [2007-11-27 7:51:03]
# 1
> table.setPreferredScrollableViewportSize(panel.getSize());If you want the two to be the same size, why mess with the scrollPane to begin with?Anyway, I'm probably misunderstanding your intent, and there's a Swing forum that is frequented by smarter Swing people than I
kevjavaa at 2007-7-12 19:32:09 > top of Java-index,Java Essentials,New To Java...
# 2
I want the ScrollPane to begin with the same size of the JPanel, but the table to be smaller then both of them.This way, I've tried to stretch the table, so the ScrollPane would be initially the same size as the panel, but it didn't work.
Valerianoa at 2007-7-12 19:32:09 > top of Java-index,Java Essentials,New To Java...
# 3

On this picture, there is a grey space between the end of the table and the end of the window: http://java.sun.com/docs/books/tutorial/figures/uiswing/components/TableRenderDemo.png

This is because the JScrollPane resizes itself, to fit the size of the table, but I want it not to resize like that if the table is smaller then the Panel, so there will be a blank space between the end of the table and the end of the JScrollPane and not between the end of the JScrollPane and the end of the window.

Valerianoa at 2007-7-12 19:32:09 > top of Java-index,Java Essentials,New To Java...