如何更改 jtable 中的默认停止编辑行为

发布于 2024-07-25 00:37:15 字数 184 浏览 3 评论 0原文

当您编辑 jtable 中的单元格时,仅当焦点更改或按下 Enter 键时,该值才会永久保存(例如,如果您将单元格值从“abc”更改为“xyz”并关闭窗口,则编辑将丢失) 。 当用户停止编辑时如何使编辑永久化?

我想我们必须在编辑单元格值时更新单元格值,但我不知道如何更新。 任何帮助表示赞赏!

提前致谢!

When you edit a cell in an jtable the value is made permanent only if the focus is changed or if one hits enter (for example if you change the cell value from "abc" to "xyz" and close the window the edit is lost). How do i make the edit permanent when the user stops editing?

I guess we have to update the cell value as the cell value is being editted but i am not sure how. Any help is appreciated!

Thanks in advance!

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

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

发布评论

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

评论(2

许你一世情深 2024-08-01 00:37:16
// tell JTable to stop editing and save any changes when the table
// loses focus. This means edits will be saved when clicking on 
// another component, eg: button.
table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
// tell JTable to stop editing and save any changes when the table
// loses focus. This means edits will be saved when clicking on 
// another component, eg: button.
table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
吾性傲以野 2024-08-01 00:37:16

我会在单元格上设置一个 ActionListener,在每次击键后将单元格的值保存到变量中(假设单元格具有焦点)。 然后,无论窗口发生什么情况,该变量仍将包含单元格中当前的内容。 很简单。

I would setup an ActionListener on the cell that saves the value of the cell to a variable after every keystroke (assuming the cell has focus). Then no matter what happens to the windows this variable will still contain whatever was currently in the cell. Pretty simple.

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