开发者

Default display area of JScrollPane in Java

I have the following problem: I have a JTable insi开发者_StackOverflow中文版de a JScrollPane, and the table has 20 rows. However I want the JScrollPane to only display 10 row at a time (thus one has to scroll down to see the rest of the rows). I am using GridBagLayout to position the JScrollPane.

Any suggestion? Thanks.


table.setPreferredScrollableViewportSize(...);

You can get the preferred width by using the getPreferredSize() method of the table.

You will need to caclulate the height to be the height of the table header plus the height of the rows which can be determine by using table.getRowHeight().


If you know the height of the rows then you can put the JScrollPane in panel with an explicit height - getting the explicit height on the panel WRT the layout manager might be the hard part.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜