简体   繁体   English

如何使用Jframe或JPanel粘贴JScrollPane的边框?

[英]How to stick down border of JScrollPane with the Jframe or JPanel?

I mean when I resize the frame to the left or right side the table automatically resizes itself but I want the same future when I resize it from down or up sides of the table. 我的意思是,当我将框架的大小调整到左侧或右侧时,表格会自动调整大小,但是当我从表格的下方或上方调整大小时,我希望拥有同样的未来。 There is scroll for down and up but I want default size to be smaller. 有上下滚动,但我希望默认尺寸较小。

In fact aJScrollPane.setSize() doesn't work, aJPanel.setSize() too. 实际上, aJScrollPane.setSize()无效, aJPanel.setSize()aJPanel.setSize() Can you help me? 你能帮助我吗?

If you are trying to restrict the number of rows the table displays by default, you can use JTable.setPreferredScrollableViewportSize() . 如果尝试限制默认情况下表格显示的行数,则可以使用JTable.setPreferredScrollableViewportSize() For example for 10 rows you can do the following: 例如,对于10行,您可以执行以下操作:

table.setPreferredScrollableViewportSize(
        new Dimension(table.getPreferredScrollableViewportSize().width, 
                10 * table.getRowHeight())); 

Note however, table rows can have variable heights. 但是请注意,表格行的高度可以变化。 Also note, that hard-coding sizes in general can have side effects. 还要注意,硬编码大小通常会产生副作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM