Re: Ditching focus of a JTextField



The answer for me was two parts.

1) make the ActionEvent do a "mainPane.requestFocus();" mainPane is my
all-encompasing JPanel. When it gets focus, you can't really tell it has
it, so that is good enough for me.

2) create a FocusListener where the focusLost method does all the real work.
It gets called when the user clicks off somewhere else, and also when the
mainPane takes focus as directed in the ActionEvent.

Thanks for all the help,

Rob

> I have implemented a simple JTextField in my application. I am using an
> ActionListener to perform an action when the user presses enter after
> completing input. This works fine....
>
> However, after pressing enter, the cursor remains blinking in the box.
The
> user has no feedback that his input has been accepted. I need to force
the
> focus away from the textfield after input is complete. However, I don't
> really want focus to go anywhere else in particular....
>
> Also, is there an event that triggers when a user manually changes focus
off
> of the text box? I would like my action to occur any time the user
changes
> the value (once they're done typing and has changed focus by clicking on
> something else), not just when the user presses enter.


.