JTable 不向上滚动
我有 JScrollPane 和 JTreeTable。通常,我的 JTable 包含很多项目,应用程序必须将焦点设置到树表中的特定行并滚动到它。 我使用以下推荐的代码来设置焦点:
table.scrollRectToVisible(table.getCellRect(rowIndex, vColIndex, true));
出于某种原因,仅当新选择的行位于当前可见行下方时才有效。但是,当程序要求选择当前可见行上方的不可见行时,它根本不会滚动到该位置。 我已经用谷歌搜索了很多关于这个问题的信息,但还没有找到任何解决方案。有人知道如何解决这个问题吗? 先感谢您。
I have JScrollPane with a JTreeTable. Typically my JTable contains a lot of items and app must set focus to specific row in treetable and scroll to it.
I'm using the following recommended code to set focus:
table.scrollRectToVisible(table.getCellRect(rowIndex, vColIndex, true));
For some reason that works only if the newly selected row is below the current visible rows. But when the program asks to select an invisible row that is Above the current visible row it doesn't scroll to that position at all.
I've googled a lot about the issue but haven't found any solution yet. Has someone an idea how to fix that problem?
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
scrollRectToVisible() 方法仅确保矩形在视口中可见。我相信您可以使矩形与视口大小相同,以强制滚动,即使起点可见。
更简单的方法是使用:
The scrollRectToVisible() method only makes sure the rectangle is visible in the viewport. I believe you can make the Rectangle the same size as the viewport to force a scroll even when the starting point is visible.
An easier approach is to use:
为了处理向上滚动条件,以下解决方法对我有用:
To handle the scroll up condition the following work-around worked for me: