I've been wanting to update database information from a panel field when the focus is lost. Turns out that the focusLost() method is called only if some other component gets the focus. Then I came across the shouldYieldFocus method of the InputVerifier class. Even though (in some cases) I did not need to verify the input, I could gain control (or remain in the field if the value was "bad"), I could at least update the database value with the changed value of the field. Well, it appears that the shouldYieldFocus() has the same issue as the focusLost() method: the focusLost() is not called if, say, the close window (the "X") is clicked.
So, my question is: does the shouldYieldFocus() work the same way as focustLost() in this regard?
generally, there are better listeners than focusLost()
what is your 'panel field' and what is to
be saved to the db - perhaps there's a
Joined: May 21, 2012
My application is a genealogy program. The panel fields (Components) are JTextFields and JComboBoxes that are for the person's name, gender, dates, locations, etc. (The only real verification I need is to make sure the date field is a valid date, but that's not related to my problem.) Basically, when the component loses the focus, I assume the user is done with entering/editing the data, and I would like to grab that data and stuff it somewhere (assume a temp location before sending to the database). I don't really want to respond at a keystroke level. Is there a better way to tell if a user is done with the data than a focusLost() or shouldYieldFocus() method?
Joined: Jun 09, 2003
One way might be to include an 'update/save' button so the user triggers when he's finished.
also include a windowListener for windowClosing() to check whether the data's been saved
and if not, pop-up an optionPane to confirm close without save.