Re: focusLost vs. actionPerformed




"Richard F.L.R.Snashall" <rflrs@xxxxxxxxxxxxx> wrote in message
news:INGdnXYp9sanyITYnZ2dnUVZ_oSdnZ2d@xxxxxxxxxx
I have a number of JTextField components that allow user entry.
I have set up both an ActionListener and a FocusListener so that,
for either actionPerformed or focusLost, the value is examined
for validity. If it is invalid, a message dialog is put up
indicating the unacceptable entry.

I leave the user input in the JTextField while the message dialog
is up to allow the user to mentally acknowledge the error, but
replace the old input value when the message dialog is done.

However, if the bad input is via actionPerformed, acknowledging
the message dialog seems to cause a loss of focus. On at least
my machine, the focusLost process is started before completion
of the actionPerformed process. As a result, as the bad value
is still in the input field, the message dialog comes up again.

Is this something that can be counted upon (ignoring focusLost
while actionPerformed is running), or do I need to take some kind
of additional precautions?

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
has to look elsewhere to view information necessary to input the
correct info. But when she tries that, bang! - you force thiis dialog
up, she acknowledges it, and you send focus back to the offending
text field. Then she tries to go elsewhere to find the info, and you pop up
the dialog again. She in frustration then abandons anything to do with
that program.
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Software Reuse Project


.



Relevant Pages

  • Re: FocusListener usage?
    ... Before the above post I tried to setup an ActionListener on the JButton ... I placed a sysout command in the 'actionPerformed' method but never see it. ... I do get to the proper 'focusGained' and 'focusLost' events as I believe I ...
    (comp.lang.java.programmer)
  • focusLost vs. actionPerformed
    ... I have a number of JTextField components that allow user entry. ... I have set up both an ActionListener and a FocusListener so that, ... for either actionPerformed or focusLost, ...
    (comp.lang.java.gui)
  • Re: Combo Box event fun
    ... appropriate checkbox? ... something that would cause a problem (such as removethe actionListener)? ... Have you tried running it in a debugger, or added some debugging print lines ... Boeing Associate Technical Fellow ...
    (comp.lang.java.gui)
  • Re: TextField
    ... RadioButt., comboBox... ... public void actionPerformed{ ... all the buttons, texts, etc.) implement ActionListener. ... Boeing Associate Technical Fellow ...
    (comp.lang.java.programmer)