无法从 JTable 可编辑单元格中读取数据
Unable to read data from JTable editable cell
我是直接向JTable中插入数据,假设JTable中有5行,我全部插入了值,最后我在第五行的单元格中插入值,并且单元格处于可编辑模式,在这种情况下我无法从那个单元格读取数据。
在 JTable
中的单元格设置或获取值之前,您必须 cancel/stop editing.You 可以通过
假设 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();
或
/**
* Tells the editor to cancel editing and not accept any partially
* edited value.
*/
jTable1.getCellEditor().cancelCellEditing();
我是直接向JTable中插入数据,假设JTable中有5行,我全部插入了值,最后我在第五行的单元格中插入值,并且单元格处于可编辑模式,在这种情况下我无法从那个单元格读取数据。
在 JTable
中的单元格设置或获取值之前,您必须 cancel/stop editing.You 可以通过
假设 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();
或
/**
* Tells the editor to cancel editing and not accept any partially
* edited value.
*/
jTable1.getCellEditor().cancelCellEditing();