I am creating a level editor for my game. I have a properties panel where I can change selected objects with my properties. I also have a Save button to write the xml level.
When editing a text field (*) when the editor button is pressed, focus or Enter is lost . This works fine, but the only problem is that when I have this sequence of actions:
- Change field
- Click save button
Because what happens is:
- I edit the field
- I click save
- Level saved
- The field has lost focus
- Editing is sent
As you can see, this is the wrong order. Of course, I want the field to lose focus, which leads to submit and then keep the level.
Is there a trick, hack or workaround to make the field lose focus first, and then execute the save button action listener?
Thanks in advance.
(* submit = field editing is also performed in the property of the object)
EDIT : for the field, I am using FocusAdapter with focusLost :
FocusAdapter focusAdapter = new FocusAdapter() { @Override public void focusLost(FocusEvent e) { compProperties.setProperty(i, getColor()); record();
And for the button, a simple ActionListener with actionPerformed`.
btnSave.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) {
Martijn courteaux
source share