相当于Java到C#文本框TextChanged事件 [英] Java equivalent to C# TextBox TextChanged event

查看:581
本文介绍了相当于Java到C#文本框TextChanged事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中存在的文本框的事件如下:

in C# there is an event for textboxes as follows

private void fooText_TextChanged(object sender, EventArgs e)
{
    //do something 
}

在fooText_TextChanged代码一旦文本中的文本被改变解雇了。

the code in the fooText_TextChanged is fired once the text within the textbox is altered.

什么是相当于这个Java?或如何可以类似于这样用Java来实现吗?

What is the java equivalent to this? Or how can something similar to this be achieved in java?

感谢您的任何反馈/咨询/建议。

Thanks for any feedback/help/advice.

推荐答案

有关摇摆,如果你想被通知的 的文本组件的文本改变了之后,你会使用被添加到的JTextComponent的文件一个的DocumentListener。例如,

For Swing, If you wanted to be notified after the text component's text had changed, you'd use a DocumentListener that was added to the JTextComponent's Document. e.g.,

  JTextField myField = new JTextField();

  myField.getDocument().addDocumentListener(new DocumentListener() {

     public void removeUpdate(DocumentEvent e) {
        // TODO add code!

     }

     public void insertUpdate(DocumentEvent e) {
        // TODO add code!

     }

     public void changedUpdate(DocumentEvent e) {
        // TODO add code!

     }
  });

如果在另一方面,你想检查文本的的有一直致力于文本组件,你一个DocumentFilter上添加到的JTextComponent的文件。

If on the other hand, you wanted to check text before it has been committed to the text component, you'd add a DocumentFilter to the JTextComponent's Document.

这篇关于相当于Java到C#文本框TextChanged事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆