Swing GUI:当 JTable 变大时滚动不会更新
我有一个 Java Swing GUI,但在 JScrollPane
中的 JTable
遇到了问题。 由于某种原因,当程序执行期间表模型的行数增加时,JScrollPane
不会更新 - 也就是说,如果行数增加使得表的高度超过了滚动视图的高度,滚动窗格没有按预期更新。 (新行按预期显示在屏幕上)。 如果调整窗口大小,滚动会按预期更新。
垂直滚动策略是VERTICAL_SCROLLBAR_AS_NEEDED
,表模型fireTableDataChanged
被调用。
不幸的是代码有点复杂,所以我无法提供导致问题的代码示例。 但想问问是否有人有一些直接的想法。
编辑:还有一点更令人困惑:水平滚动策略是HORIZONTAL_SCROLLBAR_AS_NEEDED
,并且表格宽度是否超过视图宽度(即使用水平滚动条),不会发生此问题...
编辑2:问题不在于表格应该滚动,而是滚动条未激活,因为它们应该。
I got a Java Swing GUI and got a problem with a JTable
in a JScrollPane
. For some reason, when the rows of the table model are increased during the program execution, the JScrollPane
isn't updated - that is, if the rows are increased so that the height of the table is over the height of the scroll view, the scroll panes aren't updated as supposed. (The new rows are shown at the screen as expected). If the window is resized, scrolling is updated as expected.
The vertical scrolling policy is VERTICAL_SCROLLBAR_AS_NEEDED
, table models fireTableDataChanged
is called..
Unfortunately the code's a bit complex so I can't provide an code sample causing the problem. But thought to ask if somebody got some ideas straight..
EDIT: Still a bit more confusing : horizontal scrolling policy is HORIZONTAL_SCROLLBAR_AS_NEEDED
, and if the table width if over the view width (that is, the horizontal scrollbar is used), this problem doesn't occur...
EDIT2: The problem isn't that the table should be scrolled but that the scrollbar's aren't activated as they should.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能需要发布一些代码。 我刚刚完成了以下测试,它的工作原理如广告所示,即当行数超过视口高度时激活垂直滚动条:
You might need to post some of your code. I've just knocked up the following test and it works as advertised, i.e. vertical scrollbars are activated when the number of rows exceeds the viewport height:
嗯..返回问题后,我发现 JScrollPane 中的行标题自定义导致了问题。 (一些首选尺寸设置为不太合理的值等)..
Hmm.. after returning to the issue I found out that our row header customizing in JScrollPane was causing the problem. (Some preferredsizes were set with not-so-sensible values etc)..