Retaining focus

Hi,

I have two required JTextFields with FocusListeners (I extend FocusAdapter). Before losing focus on the first field I want to check the value so my focusLost() performs a check and if it is unusually low (but still legal) I put up a JOptionPane.showConfirmDialog() asking to confirm the data YES or NO. If they click NO I want to retain focus so I perform a requestFocus() on the text field before returning to the focusLost() method but it doesn't work, focus still transfers to the next JTextField.

QUESTION - What is the proper way to retain focus?

Thank you, I will try to put some Duke Stars on this question.

[644 byte] By [hopia] at [2007-11-27 8:09:58]
# 1
yeah what your trying makes sense but doesn't work; I've tried it before.One suggestion would be to disable (setEnabled(false) everything else. Would that work for you?
tjacobs01a at 2007-7-12 19:53:17 > top of Java-index,Java Essentials,Java Programming...
# 2
Swing related questions should be posted in the Swing forum.You can use an IputVerifier. Check out this example from the Swing forum. It shows how to popup a dialog: http://forum.java.sun.com/thread.jspa?forumID=57&threadID=776107
camickra at 2007-7-12 19:53:17 > top of Java-index,Java Essentials,Java Programming...
# 3

Hi,

I tried to keep my example simple but I see now must reveal that there are other text fields and combo boxes on the screen. I am quite sure the user would subvert my logic by clicking on another field in the window after fixing the data and thus the next focus receiver would be different and I wouldn't know if or what object I had disable focus on previously. Does that seem like a trap to you as well?

Thank you.

hopia at 2007-7-12 19:53:17 > top of Java-index,Java Essentials,Java Programming...
# 4

Hi,

I will test this approach. I had some difficulty with this approach before but I was testing for the condition from within the shouldYieldFocus() method. I know I encountered the issue of putting up a dialog from within the verify() and turned off the verifier but I think a design flaw in the software kept me from being successful. I know a little more now and maybe I can get this to work this time. I'll reply again.

Thanks for responding.

hopia at 2007-7-12 19:53:17 > top of Java-index,Java Essentials,Java Programming...
# 5
I find that drinking Red Bull helps me retain focus or it makes me jittery I can never remember.PS.
puckstopper31a at 2007-7-12 19:53:17 > top of Java-index,Java Essentials,Java Programming...