Mohamed Bawaneen
Mohamed Bawaneen

Reputation: 101

Value Change Listener to JTextField

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.

 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 
  }
  }  

Upvotes: 1

Views: 11190

Answers (1)

Angad Tiwari
Angad Tiwari

Reputation: 1768

    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
    }
  }
});

Upvotes: 5

Related Questions