我直接在JTable中插入数据,假设JTable中有5行并且我全部插入了值,最后我在第五行的单元格中插入了值,并且该单元格处于可编辑模式,在这种情况下,我无法从中读取数据该单元格。
Before you set or get value from a cell in JTable
you have to cancel/stop the editing.You can do this by
Assume jTable1
is the varaible name of the 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();
or
/**
* Tells the editor to cancel editing and not accept any partially
* edited value.
*/
jTable1.getCellEditor().cancelCellEditing();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.