java JTextField 的值更改侦听器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26443352/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 09:56:11  来源:igfitidea点击:

Value Change Listener to JTextField

javajtextfield

提问by Mohamed Bawaneen

I want to know the equivalent event same like change event in VB i have text box field and i would like to trigger the code once user made any changes, in text box values ,i need to know how to stick listener to my text box currently am using KeyReleased event.

我想知道与 VB 中的更改事件相同的等效事件我有文本框字段,我想在用户对文本框值进行任何更改后触发代码,我需要知道当前如何将侦听器粘贴到我的文本框我正在使用 KeyReleased 事件。

 private void jTsearchKeyReleased(java.awt.event.KeyEvent evt) {  
 String jtr=jTsearch.getText();
 Boolean Txtval=StringUtils.isNumeric(jtr);
  if (Txtval=false) 
   // my code will come here 
  }
  }  

回答by Angad Tiwari

    jTsearch.getDocument().addDocumentListener(new DocumentListener() {
    public void changedUpdate(DocumentEvent e) {
        //whatever you want
    }
    public void removeUpdate(DocumentEvent e) {
       //whatever you want
    }
    public void insertUpdate(DocumentEvent e) {
      //whatever you want
    }
  }
});