title: Trigger a button when exactly 13 characters in text field
body: <p>I have a text field and a Search button. If the user enters precisely 13 digits (a barcode) then I want to trigger the Search automatically.</p>
  
  <p>I have a DocumentListener on the text field and am processing the insertUpdate method to determine that 13 digits have been entered. I could call the search code directly at that point (and it does work) but although the 13th character has been typed, it isn't actually displayed on the screen until the search has completed.</p>
  
  <p>I would prefer instead to trigger the Search button and have tried two ways:</p>
  
  <pre><code>DocumentListener dlBarcode = new DocumentAdaptor() {
      public void insertUpdate(DocumentEvent e) {
          String value = jtBarcode.getText();
          if (isBarcode(value)) {
              ActionEvent ae = new ActionEvent((Object)jbSearch,
                               ActionEvent.ACTION_PERFORMED, "");
              Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(ae);
          }
      }
  };
  </code></pre>
  
  <p>The second is to use:</p>
  
  <pre><code>jbSearch.dispatch(ae);
  </code></pre>
  
  <p>Neither method appears to cause the ActionListener on jbSearch to be triggered. Can you please suggest what I am doing wrong?</p>