只要单元格失去焦点,Jtable可以保存数据吗? [英] Can a Jtable save data whenever a cell loses focus?

查看:393
本文介绍了只要单元格失去焦点,Jtable可以保存数据吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

高级别:我有一个用户可用来编辑数据的JTable。

The high level: I have a JTable that the user can use to edit data.

每当用户按Enter或Tab键完成编辑时,数据都会被保存(我很高兴保存的确意味着TableModel的setValueAt()方法被称为。)

Whenever the user presses Enter or Tab to finish editing, the data is saved (I'm asusming that "saved" really means "the TableModel's setValueAt() method is called".)

如果用户在制作后以任何其他方式离开单元格编辑时,不会保存新数据,并且值保持原样。因此,例如,如果用户更改了某个值,然后点击了屏幕上的其他小部件,则更改不会坚持。

If the user leaves the cell in any other way after making an edit, the new data is not saved and the value stays the way it was. So, for example, if the user changes a value and then clicks on some other widget on the screen, the change doesn't "stick."

我相信这一点是一个充满字符串的JTable的默认行为,是吗?

I believe that this is the default behavior for a JTable full of Strings, yes?

由于各种原因,所需的行为是单元格在用户保存任何和所有编辑时离开牢房。让Swing做到这一点的最佳/正确方法是什么?

For a variety of reasons, the desired behavior is for the cell to save any and all edits whenever the user leaves the cell. What's the best/right way to get Swing to do this?

推荐答案

表停止编辑解释了发生了什么,并提供了几个简单的解决方案。

Table Stop Editing explains whats happening and gives a couple simple solutions.

这篇关于只要单元格失去焦点,Jtable可以保存数据吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆