• Advertisement
Sign in to follow this  

[java] catch all changes to a JTextField

This topic is 3321 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I added an ActionListener but the code that reads from the text field is only triggered when/if enter is pressed after typing. I also tried placing the read from text field code in a DocumentListener and each of its three overload functions but then it only triggered when the adjacent associated tree node chnaged. How do I trigger code to run when the text in the field changes? when text field looses focus, text is changed, or field is tabbed away from.

Share this post


Link to post
Share on other sites
Advertisement
Yeah, I read that tutorial, it uses an action listener which only executes if the user hit the enter key, I need to know when the user modifies the field in any way.

Share this post


Link to post
Share on other sites
I think that might have something to do with windowing. Look into window selection/deselection regarding text field losing focus or being tabbed away from.

Share this post


Link to post
Share on other sites
Quote:
Original post by NumberXaero
How do I trigger code to run when field is tabbed away from, or when text field looses focus


Use a FocusListener.

textField.addFocusLister(myFocusListener);

Focus Listener Reference

Quote:
Original post by NumberXaero
How do I trigger code to run when ... when text is changed,


http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JTextField.html

Quote:
In the JTextComponent based components, changes are broadcasted from the model via a DocumentEvent to DocumentListeners. The DocumentEvent gives the location of the change and the kind of change if desired.


Use a DocumentListener.

textField.getDocument().addDocumentListener(myDocListener);

Document Listener Reference

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement