在编辑 JTable 时读取单元格值
Read cell value in JTable while it is being edited
请指导我如何在处于编辑模式(正在编辑)时读取 jtable 单元格的值。我在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();
}
建议我如何解决这个问题。
and directly press save button
因此您需要在执行保存之前停止对单元格的编辑。
您可以使用:
table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
当您创建 table 时。
或使用:
if (table.isEditing())
table.getCellEditor().stopCellEditing();
在您的按钮的 ActionListener
中。
查看 Table Stop Editing 了解更多信息。
请指导我如何在处于编辑模式(正在编辑)时读取 jtable 单元格的值。我在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();
}
建议我如何解决这个问题。
and directly press save button
因此您需要在执行保存之前停止对单元格的编辑。
您可以使用:
table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
当您创建 table 时。
或使用:
if (table.isEditing())
table.getCellEditor().stopCellEditing();
在您的按钮的 ActionListener
中。
查看 Table Stop Editing 了解更多信息。