JTable 不向上滚动

发布于 2024-12-15 01:06:04 字数 326 浏览 5 评论 0原文

我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦里兽 2024-12-22 01:06:04

scrollRectToVisible() 方法仅确保矩形在视口中可见。我相信您可以使矩形与视口大小相同,以强制滚动,即使起点可见。

更简单的方法是使用:

scrollPane.getViewport().setViewPosition(...);

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:

scrollPane.getViewport().setViewPosition(...);
鼻尖触碰 2024-12-22 01:06:04

为了处理向上滚动条件,以下解决方法对我有用:

table.scrollRectToVisible(table.getCellRect(0, 0, true));
table.scrollRectToVisible(table.getCellRect(rowIndex, vColIndex, true));

To handle the scroll up condition the following work-around worked for me:

table.scrollRectToVisible(table.getCellRect(0, 0, true));
table.scrollRectToVisible(table.getCellRect(rowIndex, vColIndex, true));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文