JTable刷新
我使用带有水平和垂直滚动条的 JTable。我的 JTable 在包含数据的行之后有空白空间。 当我打开位于表格下方的面板时,它隐藏了 JTable 的一部分,并且滚动出现在 JTable 上。这是正常行为,但是当我关闭该面板时,没有数据的空白空间变成灰色而不是白色。 仅当我的 JTable 上有水平滚动条时才会发生这种情况。我想我必须强制 JTable 重新绘制,我在 TableHeader
和 JTable
上尝试了 resizeAndRepaint()
但它不起作用。
请帮忙!谢谢! 如果对表执行任何调整大小操作,则会调用以下 resize() 代码
for (int i = 0; i < columsNum; i++){
TableColumn column = this.getColumnModel().getColumn(i);
int preferedSize = //current size
int minimumSize = // min size
if (minimumSize != ColumnSizeCalculator.UNDEFINED_WIDTH)
column.setMinWidth(minimumSize);
column.setPreferredWidth(preferedSize);
}
this.revalidate();
this.repaint();
I use JTable with horizontal and vertical scrollbars. My JTable has empty space after rows with data.
When I open panel that is situated down of my table it hides a part of JTable and scrolling appears on JTable. This is normal behavior, but then I close that panel, empty space without data becomes grey instead of white color.
This only happens when I have horizontal scrollbar on my JTable. I suppose I must force JTable to repaint, I tried resizeAndRepaint()
on TableHeader
and JTable
but it didn't work.
Please help! Thanks!
Here is resize() code invoked if any resize action was performed on table
for (int i = 0; i < columsNum; i++){
TableColumn column = this.getColumnModel().getColumn(i);
int preferedSize = //current size
int minimumSize = // min size
if (minimumSize != ColumnSizeCalculator.UNDEFINED_WIDTH)
column.setMinWidth(minimumSize);
column.setPreferredWidth(preferedSize);
}
this.revalidate();
this.repaint();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,JTable 不会在垂直方向填充滚动窗格的视口。尝试调用
您的桌子,然后重新粉刷桌子应该可以。
By default, a JTable does not fill the viewport of a scrollpane in the vertical direction. Try to call
on your table, then repainting the table should work.