JTable:双击应保留先前的选择

发布于 2024-12-22 07:33:13 字数 325 浏览 3 评论 0原文

我有一个 JTable,我可以在其中选择一个或多个单元格。我还想对双击做出反应,为选定的单元格执行一些额外的操作。但问题是,当用户双击时,选择更改为单击的单元格。但我想在双击时保留先前的选择,这样我就可以处理所有选定单元格的双击。

编辑:
与此问题相关:
Java:忽略双击上的单击?
但我希望,对于我的情况有一个更好/更简单的解决方案。

I have a JTable where I can select one or more cells. I also want to react on double-click for doing some extra action for the selected cells. But the problem is, when the user double-clicks, the selection changes to the clicked cell. But I want to keep the prior selection on double-click, so I can handle the double-click for all selected cells.

EDIT:
Related to this question:
Java : ignore single click on double click?
But I hope, there is a better/easier solution for my case.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

盛夏尉蓝 2024-12-29 07:33:13

问题是,第一次单击时,第一个事件就会消失。稍后,第二次点击可能会出现,也可能不会出现。所以第一次点击事件确实什么都不知道。正如在建议的解决方案中,计时器可能会做的那样。

还可以做的是在第一次单击时不选择任何内容,但稍后调用一个特殊的选择事件。

SwingUtilities.invokeLater(myRunnable);

并在处理双击/myRunnable 时真正的选择。但时机可能是不可避免的。

The problem is, that on the first click the first event goes out. A bit later the second click might come or not. So the first click event does know nothing. As in the proposed solution a timer might do.

What also might do is on the first click to select nothing, but invoke a special selection event a bit later.

SwingUtilities.invokeLater(myRunnable);

and on handling the double click/myRunnable the true selection. Timing might be unavoidable though.

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