I created a simple form to edit a field. It contains only one field which has a database table field as dataprovider.
There is a button ‘OK’ to save and a button ‘Cancel’ to rollback. I don’t use transaction.
On Cancel I call “databaseManager.rollbackEditedRecords();”
I have notice that if you change the value in the field then click outside but not on any button, the value is saved automatically. And even if you click cancel it doesn’t rollback. However if you click cancel just after the edition (without clicking outside) it rollsback.
I have found that you could disable the autosave using “databaseManager.setAutoSave(false);”
So now I put it to false just before opening the form. But it still saves it when you click outside.
My issue is a little different.
I’ve got a JLabel bean acting as a button with a cancel() method on it.
The cancel() contains one line only databaseManager.rollbackEditedRecords().
I click in the field, type text, then click the button. The method runs but changes are not rollbacked.
I click in the field again (focus has been removed from field and set onto JLabel after the cancel()), then click ‘cancel’ again and only then it rolls back.
If I tab out of the field right after I type in it and only then click ‘cancel’ then the rollback works as expected.
jcompagner:
how does the label doe its stuff? how does it act as a button?
Are you sure that the label gets focus (normally labels don’t get focus)
Johan, the JLabel has a mouseClick listener and whenever it captures the event my method is run.
I also do the elements.mylabel.requestDefaultFocus() (is this one silly? seems to work )
a label doesn’t get focus when it has a mouse listener. but i guess if you request the default focus it could get the focus
But when you call that it is not so that then also the focus is already transferred.
So directly after that call your label doesn’t have focus yet.
so maybe what you could do is something like
on mouse pressed → requestDefaultFocus()
on mouse released → do your stuff.