Force JTable to "commit" data to model while it is still in editing mode

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();
}

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();

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.

Tags:

Java