title: Why the keypress is not work correctly in java
body: <pre><code>private void textFieldNameKeyPressed(java.awt.event.KeyEvent evt) {                                         
      // TODO add your handling code here:
      if(!textFieldName.getText().isEmpty())  
          buttonFinish.setEnabled(true);
      else 
          buttonFinish.setEnabled(false);
  }   
  </code></pre>
  
  <p>I just want to control <code>buttonFinish</code>'s enable by if there is text in the <code>textFieldName</code>. </p>
  
  <p>However, when I test it it always got wrong as when I input 1 letter, the  <code>setEnabled</code> won't change. </p>
  
  <p>Only if input more it will be correct. Also when I use backspace, or when clear all letters it won't change <code>setEnabled</code> back to false. Only when I click backspace one more time afterwards it will change.  What am I doing wrong?</p>