[英]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 谢谢
use DocumentListener for listening of changes in JTextArea 使用DocumentListener监听JTextArea中的更改
from this Listener you can to fire a new event to PropertyChangeListener 从此侦听器中,您可以向PropertyChangeListener触发新事件
fire a new event to PropertyChangeListener
only in the case thats required, no idea from this description, for better help sooner post an SSCCE 仅在需要的情况下向PropertyChangeListener
触发一个新事件,此描述不知道,以便更好地帮助尽早发布SSCCE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.