无法从JTable可编辑单元格读取数据

时间:2015-06-21 14:43:26

标签: java swing jtable

我直接将数据插入到JTable中,假设JTable中有5行,我在所有中插入值,最后我在第五行的单元格中插入值,并且单元格处于可编辑模式,在这种情况下我不能从该单元格中读取数据。

1 个答案:

答案 0 :(得分:0)

JTable中设置或获取某个单元格的值之前,您必须取消/停止编辑。您可以通过

执行此操作

假设jTable1JTable

的可变名称
/**
 * 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();