如何仅对 JTable 的一部分禁用双击?
我有一个启用了行选择的 JTable
。在今天之前,我想要的功能是双击任何给定行以打开一个新窗口。在今天之前,这种方法效果很好。
我刚刚在表中添加了一列 JCheckBox
es。一般来说,选择和取消选择新列中的各个复选框效果很好。但是,如果我选择一个复选框并快速取消选择它,该表会将我的操作解释为双击该复选框的行,这不是我想要的。
有没有办法仅禁用复选框的双击行为,但保持启用行选择?如果不是,那么仅禁用表的一列的行为怎么样?如果是这样,怎么办?
I have a JTable
with row selection enabled. Before today, my desired functionality was for double-clicking on any given row to open up a new window. And before today, that worked just fine.
I've just added a column of JCheckBox
es to the table. Selecting and deselecting individual checkboxes in the new column works fine, in general. However, if I select a checkbox and quickly deselect it, the table interprets my actions as a double-click on the checkbox's row, which is not what I want.
Is there a way to disable the double-clicking behavior for just the checkboxes, but keeping row selection enabled otherwise? If not, how about disabling the behavior for just one column of a table? If so, how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 table.columnAtPoint(...) 方法忽略对带有复选框的列的双击。
Use the table.columnAtPoint(...) method to ignore double clicks on the columm with the checkbox.
在
MouseListener
中,您可以检查每次单击所选行的复选框的状态,如果第二次单击的状态与第一次单击的状态不匹配,则不要打开新窗口。In the
MouseListener
you could check the state of the checkbox of the selected row for each click and if the second click's state doesn't match the first click's state then don't open a new window.