Jscrollpane and jtable

Y

yashiro

Hello every body.
I have a jtable in a jscrollpane.
How to adjust the size of the scrollpane (height) to be the same of
the jtable, so that there is no vertical scroll ? because when i fixe
a size for the jcrollpane, i got a few row in my jtable, i got a big
empty space.

thank you for you help
 
A

Andrea Francia

yashiro said:
Hello every body.
I have a jtable in a jscrollpane.
How to adjust the size of the scrollpane (height) to be the same of
the jtable, so that there is no vertical scroll ? because when i fixe
a size for the jcrollpane, i got a few row in my jtable, i got a big
empty space.

thank you for you help
I'm not sure to understood you problem.
If you want to remove the vertical scrool bar use this:

jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
 
J

Jeff Higgins

yashiro said:
Hello every body.
I have a jtable in a jscrollpane.
How to adjust the size of the scrollpane (height) to be the same of
the jtable, so that there is no vertical scroll ? because when i fixe
a size for the jcrollpane, i got a few row in my jtable, i got a big
empty space.

thank you for you help

Using SimpleTableDemo.java as an example.
SimpleTableDemo is discussed here:
<http://java.sun.com/docs/books/tutorial/uiswing/components/table.html>

changing lines 73 - 74

from:
table.setPreferredScrollableViewportSize(new Dimension(500,70));
table.setFillsViewportHeight(true);

to:
table.setPreferredScrollableViewportSize
(new Dimension(500, table.getRowCount() * table.getRowHeight()));
table.setFillsViewportHeight(false);

seems to accomplish what (it seems to me) you are asking for.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top