Question

I use PropertyChangeListener for JTextFields to listen for value change, and it works normally, and when I use it with JTextArea; no errors in the code and it is compiled normally. However this method shows response when some change occur in a JTextField text value but no response when it comes to JTextArea.

This is how I wrote the code

Inside the constructor:

textField_1.addPropertyChangeListener("value", new ChangeListener());
textField_2.addPropertyChangeListener("value", new ChangeListener());
textArea.addPropertyChangeListener("value", new ChangeListener());

And somewhere inside the class:

private class ChangeListener implements PropertyChangeListener
{
    @Override
    public void propertyChange(PropertyChangeEvent e)
    {
        Object source = e.getSource();

        if ((source == textField_1) || (source == textField_2) || (source == textArea))
        {
              System.out.println("some value changed "+ source.getClass());
        }
    }
}

I use new value each time I make a change to these compomemts text value.

THanks

Was it helpful?

Solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top