简体   繁体   English

Java:JTextArea的PropertyChangeListener没有响应?

[英]Java: PropertyChangeListener for JTextArea No response?

I use PropertyChangeListener for JTextFields to listen for value change, and it works normally, and when I use it with JTextArea ; 我对JTextFields使用PropertyChangeListener来侦听更改,并且在与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 . 但是,当JTextField文本值发生某些更改时,此方法将显示响应,但是当涉及到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. 每次更改这些compomemts文本值时,我都会使用值。

THanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM