繁体   English   中英

在编辑JTable时读取其单元格值

[英]Read cell value in JTable while it is being edited

请指导我在编辑模式下(正在编辑)如何读取jtable单元格的值。 我已经在keyTyped事件中编写了以上代码。

int col = tblItem.getSelectedColumn();
int row = tblItem.getSelectedRow();
try {
    float value =  Float.parseFloat(tblItem.getModel().getValueAt(row,2).toString());
    String str = new help.StringHelp().convertFloatString(value);
    tblItem.setValueAt(str + "", row, 2);
    } catch (Exception ex) {
       ex.printStackTrace();
    }

建议我如何解决这个问题。

然后直接按保存按钮

因此,在执行保存之前,您需要停止对单元格进行编辑。

您可以使用:

table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

创建表时。

或使用:

if (table.isEditing())
     table.getCellEditor().stopCellEditing();

在按钮的ActionListener中。

查看表停止编辑以获取更多信息。

暂无
暂无

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

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