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

3

5

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 =)

Swelter answered 18/12, 2008 at 14:1 Comment(0)
P
12

You may try

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

Profession answered 18/12, 2008 at 14:7 Comment(1)
I don't know. I'm afraid it's quite undocumented. :(Profession
S
3

Thanks asalamon74, that works quite nicely.

There's debate over the thing at Sun Bug Database : Bug 4724980: JTable: Add API to control what happens to edits when table loses focus. (also other bug entries are found). The terminateEditOnFocusLost turns on "commit-or-cancel" behaviour that can be seen at the Java sources at the class JTable$CellEditorRemover

And yes, it's somewhat strange that it isn't documented at the APIs etc...

Swelter answered 18/12, 2008 at 14:42 Comment(1)
The debate's submit date is 01-AUG-2002. So it's a long issue, and still not really documented.Profession

© 2022 - 2024 — McMap. All rights reserved.