Is there an analogue to TextListener/TextEvent (of AWT's TextField) for JTextField?
Created May 4, 2012
But of course...
Swing uses a Model-View-Controller paradigm. Rather than watching the "component" for changes, you need to watch its model
For example:
Whenever the textfield contents are changed or the document is changed programmatically, you'll receive notification in your listener.
JTextField f = new JTextField();
Document doc = f.getDocument();
doc.addDocumentListener(
new DocumentListener() {
public void changedUpdate(DocumentEvent e) {
// when text/attributes change...
}
public void insertUpdate(DocumentEvent e) {
// when text inserted...
}
public void removeUpdate(DocumentEvent e) {
// when text removed...
}
});