JLabel on change text event

Giovanni picture Giovanni · Oct 16, 2010 · Viewed 9.8k times · Source

How I can retrive the event on a JLabel when change the text inside??

I have a JLabel and when change the text inside I have to update other field.

Answer

kleopatra picture kleopatra · May 1, 2011

techically, the answer is to use a PropertyChangeListener and listen to changes of the "text" property, something like

 PropertyChangeListener l = new PropertyChangeListener() {
       public void propertyChanged(PropertyChangeEvent e) {
           // do stuff here
       }
 };
 label.addPropertyChangeListener("text", l);

not so technically: could be worth to re-visit the overall design and bind to original source which triggered the change in the label