I need to do this: Value Change Listener to JTextField
I’m trying the solution of Condemwnci, but I’m getting that error in the line:
textField.getDocument().addDocumentListener(new DocumentListener()
that in my case is:
jtxtfBuscarInv.getDocument().addDocumentListener(new DocumentListener()
In my case I want update rows in a Jtable, so my method will be this:
ordenador.setRowFilter(RowFilter.regexFilter(jtxtfBuscarInv.getText(), 0));
I’m on linux, ubuntu 11.10, using Eclipse if that matters.
Edit:
I don’t understand why, but it works in next way:
textField.getDocument().addDocumentListener(this);
and then overrride the implements methods, instead of doing all in the same lines.
The two approaches to adding a
DocumentListenershould be effectively identical. The example below lists all the listeners of typeDocumentListener.classfor each event. The obvious one isDocumentListenersitself, while the anonymous inner class has the (implementation dependent) nameDocumentListeners$1. Both implement theDocumentListenerinterface. The others are part of typical text component maintenance. Note that two copies are shown, one from each listener added.Console:
Code: