Manpreet
Manpreet

Reputation: 81

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). I have written above code in keyTyped event of jtable.

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.

Upvotes: 1

Views: 447

Answers (1)

camickr
camickr

Reputation: 324108

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.

Check out Table Stop Editing for more information.

Upvotes: 4

Related Questions