title: Perform action upon completion of barcode scanning to JTextField
body: <p>I have a <code>JTextField</code> <code>barcodeTextField</code> which accepts characters from the scanned barcode using a barcode scanner. From what I know, barcode scanning is like typing the characters very fast or copy-pasting the characters on the text field. <code>barcodeTextField</code> is also used to show suggestions and fill up others fields with information (just like searching in Google where suggestions are shown as you type).</p>
  
  <p>So far I implemented this using <code>DocumentListener</code>:</p>
  
  <pre><code>barcodeTextField.getDocument().addDocumentListener(new DocumentListener() {
    public void set() {
      System.out.println("Pass");
      // Do a lot of things here like DB CRUD operations.
    }
  
    @Override
    public void removeUpdate(DocumentEvent arg0) {
      set();
    }
  
    @Override
    public void insertUpdate(DocumentEvent arg0) {
      set();
    }
  
    @Override
    public void changedUpdate(DocumentEvent arg0) {
      set();
    }
  });
  </code></pre>
  
  <p>The problem is: If the barcode scanned has 13 characters, <code>set()</code> is executed 13 times, and so with DB operations. Same goes when I type "123" to show suggestion list, <code>set()</code> is executed 3 times.</p>
  
  <p>I wanted <code>set()</code> to get executed when the user stops typing on <code>barcodeTextField</code>. In <code>Javascript/JQuery</code>, this can be done using the <code>keyup()</code> event and having <code>setTimeout()</code> method inside, <code>clearTimeout()</code> when user is still typing.</p>
  
  <p>How to implement this behavior for <code>JTextField</code> in Java?</p>