简体   繁体   English

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

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

Please guide me how can i read the value of jtable cell while it is in edit mode ( being edited). 请指导我在编辑模式下(正在编辑)如何读取jtable单元格的值。 I have written above code in keyTyped event of 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();
    }

Suggest me how can i solve this issue. 建议我如何解决这个问题。

and directly press save button 然后直接按保存按钮

So you need to stop editing on the cell before doing the Save. 因此,在执行保存之前,您需要停止对单元格进行编辑。

You can either use: 您可以使用:

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

when you create the table. 创建表时。

Or use: 或使用:

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

in the ActionListener of your button. 在按钮的ActionListener中。

Check out Table Stop Editing for more information. 查看表停止编辑以获取更多信息。

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

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