[java] catch all changes to a JTextField
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.
Try this tutorial on JTextField:
http://java.sun.com/docs/books/tutorial/uiswing/components/textfield.html
I believe there is an example that listens for updates to the JTextField as the user types.
http://java.sun.com/docs/books/tutorial/uiswing/components/textfield.html
I believe there is an example that listens for updates to the JTextField as the user types.
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.
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.
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement