0
private void txtInvCheckinSearchInputMethodTextChanged(java.awt.event.InputMethodEvent evt) {                                                           

    if(txtInvCheckinSearch.getText().length() <= 0){
        btnInvCheckinOK.setEnabled(false);
    }else{
        btnInvCheckinOK.setEnabled(true);
    }

}                                                

Did I do this right? What I am aiming for here is for the jbutton to enable itself when the jtextbox is not empty. And if jtextbox is empty, the jbutton disables itself back. (i preset jbutton to .setEnabled(false); in the windowOpened event.

smac89
  • 39,374
  • 15
  • 132
  • 179
MBN
  • 63
  • 1
  • 1
  • 7
  • 1
    Read about [`DocumentListener`](http://docs.oracle.com/javase/7/docs/api/javax/swing/event/DocumentListener.html). – Mordechai May 19 '15 at 18:41
  • i did that code in reference to a similar program i did in vb.net... anyways, what i did with it now is.... private void txtInvCheckinSearchKeyPressed(java.awt.event.KeyEvent evt) { // TODO add your handling code here: if(txtInvCheckinSearch.getText().isEmpty()){ btnInvCheckinOK.setEnabled(false); }else{ btnInvCheckinOK.setEnabled(true); } } – MBN May 19 '15 at 18:59
  • Please don't post code in comments as it is unreadable. And don't use KeyListeners with text components, instead use a DocumentListener as @MouseEvent correctly suggest. Have a look [here](http://stackoverflow.com/questions/17132452/java-check-if-jtextfield-is-empty-or-not) for more. – Hovercraft Full Of Eels May 19 '15 at 19:01

0 Answers0