How to stop editing with DefaultCellEditor when clicking a separate JBtton

I have a table with a custom TableCellEditor (extension DefaultCellEditor) with JFormattedTextField as an editor component.

Now I have a problem: when I press a separate button during editing. When the button is pressed, the editor remains “open and active” until I want it to stop editing so that the changes made are available for the operations invoked by the button.

So, how to make editing stop when you click a separate button. I tried setFocusLostBehavior (JFormattedTextField.COMMIT) for JFormattedTextField, but it did not seem to have an effect.

Hope someone has some good ideas =)

+5
source share
3 answers

You may try

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

+12
source

Thanks asalamon74, this works very well.

It discusses things in the Sun Bug database: Error 4724980: JTable: Add an API to control what happens with editing when the table loses focus. (also found other error records). The EditOnFocusLost terminal includes the commit-or-cancel behavior that can be seen in Java sources in the JTable class $ CellEditorRemover

And yes, it’s somewhat strange that it is not documented in the API, etc.

+3
source

All Articles