Search code examples
javaswingfocusjtabletablecelleditor

How to stop editing with DefaultCellEditor when a separate JBtton is pressed


I got a table with a custom TableCellEditor (extending DefaultCellEditor) with a JFormattedTextField as the editor component.

Now I got problem: when I press a separate button while editing. When the button is pressed, the editor remains "open and active" while I'd want it to stop editing so that the changes made would be available for the operations caused by the button.

So how to cause the editing to be stopped when a distinct button is pressed. I tried setFocusLostBehavior(JFormattedTextField.COMMIT) for the JFormattedTextField but it didn't seem to have effect.

Hope somebody has some good ideas =)


Solution

  • You may try

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