[英]Resize JTable/Scrollpane
It's actually an question about this .这实际上是一个关于此的问题。 How do I resize this now?我现在如何调整它的大小? I used this, I was able to resize my JPanel, but I can't find how to resize the table or scrollpane.我使用了这个,我能够调整我的 JPanel 的大小,但我找不到如何调整表格或滚动窗格的大小。 I have 10 columns and the table just stays the same size.我有 10 列,表格的大小保持不变。
Thanks in advance提前致谢
I was able to resize my JPanel, but I can't find how to resize the table or scrollpane.我能够调整 JPanel 的大小,但找不到如何调整表格或滚动窗格的大小。
The problem is that the JPanel uses a FlowLayout.问题是 JPanel 使用 FlowLayout。 A FlowLayout will respect the preferred size of any component added to the panel. FlowLayout 将尊重添加到面板的任何组件的首选大小。 So in the example code the table is displayed at its default preferred size.因此,在示例代码中,表格以其默认的首选大小显示。
A couple of solutions:几个解决方案:
getPreferredScrollableViewportSize(...)
method of the JTable
.覆盖JTable
的getPreferredScrollableViewportSize(...)
方法。 This will override the default preferred size of the table.这将覆盖表的默认首选大小。 The table may grow/shrink depending of the layout manager used.根据所使用的布局管理器,表格可能会增大/缩小。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.