简体   繁体   English

滚动时,JScrollPane中的JTable不会自动重新绘制

[英]JTable in a JScrollPane doesn't automatically repaint when scrolling

I have a JScrollPane that holds a JTable . 我有一个JScrollPane ,它持有一个JTable The table is dynamically populated from a database query. 该表是从数据库查询中动态填充的。 That all works fine and the table is getting populated, but its wider than the visible window. 一切正常,表格被填充,但是它比可见窗口宽。

I can see the left part of the table and I need to scroll right to see the right end of it. 我可以看到表格的左侧,需要向右滚动才能看到表格的右端。 When I do that, the part of the table that was hidden (right end) is blurred. 当我这样做时,表的隐藏部分(右端)变得模糊。 Then I stop scrolling and wait few seconds and then it is repainted and looks fine. 然后我停止滚动并等待几秒钟,然后将其重新粉刷并看起来不错。 I scroll back left and everything is OK - no blur. 我向左滚动,一切都很好-没有模糊。

  • I guess I'm missing some force repaint - but shouldn't JScrollPane handle it automatically ? 我想我缺少一些强制重绘-但是JScrollPane是否不应该自动处理它?
  • How do I get rid of this effect ? 我如何摆脱这种影响?

Here is how I construct it (I wont paste all the code since it basically work): 这是我的构造方式(因为它基本上可以正常工作,所以我不会粘贴所有代码):

    jScrollPane1.setAutoscrolls(true);
    jScrollPane1.getViewport().setLayout(borderLayout2);        
    jScrollPane1.getViewport().add(table, BorderLayout.CENTER);
    this.add(jScrollPane1, BorderLayout.CENTER);

Never seen such an artifact, might be due to the fact that you are adding the table in a completely wrong manner. 从来没有见过这样的工件,可能是由于您以完全错误的方式添加表的事实。 Replace the first three lines of your snippet with: 将代码段的前三行替换为:

jScrollPane1.setViewportView(table);

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

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