Java 无法从JTable可编辑单元格读取数据
我直接将数据插入JTable,假设JTable中有5行,我总共插入了值,最后我在第五行的单元格中插入值,单元格处于可编辑模式,在这种情况下,我无法从该单元格中读取数据。在设置或从Java 无法从JTable可编辑单元格读取数据,java,swing,jtable,Java,Swing,Jtable,我直接将数据插入JTable,假设JTable中有5行,我总共插入了值,最后我在第五行的单元格中插入值,单元格处于可编辑模式,在这种情况下,我无法从该单元格中读取数据。在设置或从JTable中的单元格中获取值之前,您必须取消/停止编辑。您可以通过 假设jTable1是JTable /** * Tells the editor to stop editing and accept any partially edited * value as the value of the editor.
JTable
中的单元格中获取值之前,您必须取消/停止编辑。您可以通过
假设jTable1
是JTable
/**
* Tells the editor to stop editing and accept any partially edited
* value as the value of the editor. The editor returns false if
* editing was not stopped; this is useful for editors that validate
* and can not accept invalid entries.
*
* @return true if editing was stopped; false otherwise
*/
jTable1.getCellEditor().stopCellEditing();
或
你应该添加一些代码,这样我们就可以知道你想做什么了……你是从程序的角度还是从用户的角度讲的?请记住——您必须将单元格作为用户留在GUI中,以便能够从程序端读取它。只需单击最后一个单元格外的某个位置,即可完成编辑,程序即可读取数据。
/**
* Tells the editor to cancel editing and not accept any partially
* edited value.
*/
jTable1.getCellEditor().cancelCellEditing();