Problem retaining focus

Hi all,

I do maintenance on a piece of code that, although I am not highly experienced, I believe has a design flaw that I am having difficulty getting around.

A JPanel has many instantiated MyTextFields. The public class MyTextField extends JTextField and implements ActionListener and each field has an InputVerifier and FocusListener set/added. Back in the JPanel where the text fields are instantiated with MyTextField they then have FocusListeners added to them.

When focus is lost on one of these fields the MyTextField InputVerifier and FocusAdapter are first to receive the event followed by the FocusAdapter that was added to the already instantiated text field. The original coder did not understand this I'm sure because they put into the second FocusAdapter focusLost() methods what they thought would be a trap - setting a MyTextField object flag called 'holdFocus'. The MyTextField InputVerifier verify() method is supposed to jump out of the verify() method returning false if the flag was set. But the flag gets set after the method is run. The proof of this, if it is needed, is that if I go back into the text field then exiting it takes two clicks.

QUESTION: Is there a way for me to on a case by case basis remove the first FocusAdapter and use the second one. Or something else...

Thanks for any feedback.

hopi

[1378 byte] By [hopia] at [2007-11-27 8:12:19]
# 1

> Or something else...

You where given a working example in your other posting on this topic.

There is no need for the FocusListener, only the InputVerifier.

Or maybe I don't understand you description of the problem in which case a SSCCE is required so we don't have to guess what you are talking about.

http://homepage1.nifty.com/algafield/sscce.html

camickra at 2007-7-12 19:56:40 > top of Java-index,Desktop,Core GUI APIs...
# 2

Hi,

I agree camickr that the InputVerifier should work but when I made the other post I did not realize that there was an InputVerifier on the text field and two FocusAdapters. I don't understand what affect putting a second InputVerifier on the text field would do, i.e. what would be the sequence of event handling and what if the first verifier yielded focus and the second did not. The first verifier is checking for acceptable range/values while the second is warning that the value is unusually extreme (maybe a typo, maybe they don't know what they're doing) and gives them a chance to change the value before moving on.

I hope the description is helpful as to why I didn't immediately try the code example.

hopi

hopia at 2007-7-12 19:56:40 > top of Java-index,Desktop,Core GUI APIs...
# 3
Follow up note, the InputVerifier already on the text fields is generic to all text fields and does not handle checking for extremes, only max and min.hopi
hopia at 2007-7-12 19:56:40 > top of Java-index,Desktop,Core GUI APIs...