I have an application with a JFrame containing text fields. When text in a field is modified, and the field gets a focusLost
event, it immediately writes its contents to an external database.
However, if the user quits the application while a field is still focused, the focusLost
message is not sent and the modified data is not saved.
How can I force the loss of focus on a field, perhaps in a windowClosing
method in my WindowListener
? I tried using requestFocusInWindow()
in that method, but it did not help.
Why not just call the same method that writes the contents to the external database from within the windowClosing method of your window listener?