我直接将数据插入到JTable中,假设JTable中有5行,我在所有中插入值,最后我在第五行的单元格中插入值,并且单元格处于可编辑模式,在这种情况下我不能从该单元格中读取数据。
答案 0 :(得分:0)
在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();
或
/**
* Tells the editor to cancel editing and not accept any partially
* edited value.
*/
jTable1.getCellEditor().cancelCellEditing();