It's not a secret anymore!*
The moose likes Swing / AWT / SWT and the fly likes FocusListener.focusLost() and/or InputVerifier.shouldYieldFocus() not called? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "FocusListener.focusLost() and/or InputVerifier.shouldYieldFocus() not called?" Watch "FocusListener.focusLost() and/or InputVerifier.shouldYieldFocus() not called?" New topic
Author

FocusListener.focusLost() and/or InputVerifier.shouldYieldFocus() not called?

John Duke
Greenhorn

Joined: May 21, 2012
Posts: 5
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?

Thanks!
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
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
better altetnative.
John Duke
Greenhorn

Joined: May 21, 2012
Posts: 5
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?

Thanks!
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: FocusListener.focusLost() and/or InputVerifier.shouldYieldFocus() not called?
 
Similar Threads
JtextField addKeyListener
JTextField problem
Retaining Focus in Swing
dynamic applet
doubt in focus