I have a JTable as follow.
So, while the JTable is still in editing mode (There is a keyboard cursor blinking at Dividend column), clicking OK directly will not commit the data into table model. Clicking OK merely close the dialog box.
I need to press ENTER explicitly, in order to commit the data into table model.
While JTable is still in editing mode, before closing dialog box, is there any way I can tell the JTable by saying, "Hey, is time for you to commit the changes into your model"
The source code for this dialog box is as follow Dialog Box Source Code. Do look at jButton1ActionPerformed
for the executed code when OK is pressed.
Table Stop Editing gives a couple of approaches.
EDIT
Example from article:
table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
Example from article:
if (table.isEditing())
table.getCellEditor().stopCellEditing();
I'm not sure if it will work (it would have been nice to have a SCCE), but try this:
TableCellEditor editor = table.getCellEditor();
if (editor != null) {
editor.stopCellEditing();
}
To make the whole stable stop editing completely in any state (editing or not), you can call editing stopped:
table.editingStopped(new ChangeEvent(table));
That way you don't have to check for editors/state/etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With