【问题标题】:Unable to read data from JTable editable cell无法从 JTable 可编辑单元格中读取数据
【发布时间】:2015-06-24 15:07:33
【问题描述】:

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

【问题讨论】:

  • 你应该添加一些代码,这样我们就可以知道你想要做什么......
  • 您是从程序角度还是从用户角度说话?请记住 - 您必须在 GUI 中以用户身份离开单元格才能从程序端读取它。只需单击最后一个单元格之外的某个位置,即可完成编辑,程序可以读取数据。

标签: java swing jtable


【解决方案1】:

在您设置或从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();

【讨论】:

    猜你喜欢
    • 2019-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-18
    • 1970-01-01
    • 2011-09-27
    • 1970-01-01
    相关资源
    最近更新 更多