>I have a number of JTextField components that allow user entry.
> I have set up both an ActionListener and a FocusListener so that,
[quoted text clipped - 15 lines]
> while actionPerformed is running), or do I need to take some kind
> of additional precautions?

Signature
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Software Reuse Project
> "Richard F.L.R.Snashall" <rflrs@notnotrcn.com> wrote in message
> Popping a error/warning dialog on FocusLost is usually a *bad idea*.
> The problem is that the user starts entering the info, then realizes she
[quoted text clipped - 4 lines]
> the dialog again. She in frustration then abandons anything to do with
> that program.
In its present state, I do not force the focus back to the offending
component. I basicly ignore the bad input by putting the good value
back. This does not allow the user to just edit it to a good value,
but it does preclude the problem above.
However, if I don't check the input when focus is lost, (or do you
have an alternative), it could sit there in a poor state with no
message to the user. Wouldn't that be just as poor?
That still leaves the original question. Is it a property of my
machine that the loss of focus is acted upon before the other
actionPerformed process has completed, or would that happen on all
platforms?
Fred Kleinschmidt - 26 Sep 2006 22:00 GMT
>> "Richard F.L.R.Snashall" <rflrs@notnotrcn.com> wrote in message
>
[quoted text clipped - 16 lines]
> have an alternative), it could sit there in a poor state with no
> message to the user. Wouldn't that be just as poor?
Say, for example you have 5 text fields and an OK button.
The actionPerformed of the button then checks all fields and
either performs whatever is supposed to happen (if all is OK), or
reports all errors.
I really dislike it when an error dialog pops up due to a focus lost event.
What if I am entering info and I notice that I have received an important
email?
I go to read it and - bam! - here comes this stupid dialog.
> That still leaves the original question. Is it a property of my
> machine that the loss of focus is acted upon before the other
> actionPerformed process has completed, or would that happen on all
> platforms?
When you press the acknowledge button on the dialog, this happens:
1)The item that had focus gets a focus lost (unless it was this button).
2)The button gets a focus gained (if it didn't already have it)
3) The button redraws itself as pushed
Then when you release the button,
4) actionPerformed
5) the button redraws itself in its un-pushed state
Actually, there are several other events happening, too (mouse motion,
leave, enter, etc.)

Signature
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Software Reuse Project
Thomas Weidenfeller - 27 Sep 2006 08:30 GMT
> In its present state, I do not force the focus back to the offending
> component. I basicly ignore the bad input by putting the good value
> back.
Arghhhh. I would go mad if an application does this to me. Actually, I
would avoid the application in the future on the fear that there is more
wrong with it than just a broken input window.
Imagine you are typing in a word like
pneumonoultramicroscopicsilicovolcanoconiosis.
And you are not sure if it is actually ...coniosis or ...koniosis at the
end. So you typed the word, and just want to do a quick check on the web
if it is c or k in coniosis. And bang, right before you are done with
entering the data the application deletes the input and replaces it with
"good" values. THANK YOU VERY MUCH.
Or even worse. Imagine you are, for whatever reason, distracted during
input and accidentally move the mouse outside of the window. Or someone
bumps against your table and the mouse gets accidentally moved.
> That still leaves the original question. Is it a property of my
> machine that the loss of focus is acted upon before the other
> actionPerformed process has completed, or would that happen on all
> platforms?
It does not matter.
a) Your handling of the data is anyhow faulty
b) If it happens you your machine it is likely that it happens on many
more machines.
/Thomas

Signature
The comp.lang.java.gui FAQ:
http://gd.tuwien.ac.at/faqs/faqs-hierarchy/comp/comp.lang.java.gui/
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
Richard F.L.R.Snashall - 27 Sep 2006 10:53 GMT
>> In its present state, I do not force the focus back to the offending
>> component.
> Or even worse. Imagine you are, for whatever reason, distracted during
> input and accidentally move the mouse outside of the window. Or someone
> bumps against your table and the mouse gets accidentally moved.
That could happen whatever the state of the input. Since the input
here is numeric, the odds are that what was already typed in is valid.
Tell the kitty to get off the table;-)
>> That still leaves the original question. Is it a property of my
>> machine that the loss of focus is acted upon before the other
[quoted text clipped - 4 lines]
>
> a) Your handling of the data is anyhow faulty
Actually, it is based upon existing tools, where losing focus caused
whatever data was in the field to be accepted. What I objected to in
those tools was not that it accepted the input, but that it would
accept up to the first error and quietly ignore typing errors.
> b) If it happens you your machine it is likely that it happens on many
> more machines.
Is it a property of the Java environment or of the individual platform?