简体   繁体   English

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

[英]Unable to read data from JTable editable cell

我直接在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 在设置或从JTable的单元格中获取值之前,必须先取消/停止编辑。

Assume jTable1 is the varaible name of the 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();

or 要么

/**
 * Tells the editor to cancel editing and not accept any partially
 * edited value.
 */
jTable1.getCellEditor().cancelCellEditing();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM