如何让 JTable 保留在编辑的单元格上
如果有人编辑 JTable 的单元格内容并按 Enter 键,内容就会被修改,并且表选择会移动到下一行。
是否可以禁止 JTable 在单元格编辑后转到下一行?
原因是我的程序使用 ListSelectionListener 同步单元格选择上的一些其他小部件,并且我不想在编辑当前单元格后选择下一行。
If someone edit the cell content of a JTable and press enter, the content is modified and the table selection moves to the next row.
Is that possible to forbid the JTable to go to the next row after a cell edition?
The reason is that my program synchronize some other widgets on cell selection using a ListSelectionListener, and I do not want to have the next row selected after editing the current cell.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Enter 的默认绑定是名为
selectNextRowCell
的Action
。要覆盖WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
输入映射中的条目,您需要提供doNothing()
Action
,如 如何使用键绑定:如何创建和删除键绑定。The default binding for Enter is the
Action
namedselectNextRowCell
. To override the entry in theWHEN_ANCESTOR_OF_FOCUSED_COMPONENT
input map, you'll need to supply adoNothing()
Action
, as suggested in How to Use Key Bindings: How to Make and Remove Key Bindings.我不确定具体如何执行此操作,但我会研究 动作地图。您应该能够修改或替换映射到“Enter”键的操作。
祝你好运!
I'm not sure how exactly to do this, but I would look into ActionMap. You should be able to either modify or replace the Action that is mapped to the 'Enter' key.
Good luck!