title: Perform search with return key in GUI
body: <p>I'm trying to get a jTextField to perform a search when I use the enter key. The searchButton does the search, so I need the action of a key press in the text field to trigger the searchButton's action. </p>
  
  <p>Here's what I have just now, "Enter Pressed" is displayed on the console, when I press enter in the text field.</p>
  
  <pre><code>ActionListener actionListener = new ActionListener() {
    public void actionPerformed(ActionEvent actionEvent) {
      SearchButton.getActionForKeyStroke(
        KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, false));
      System.out.println("Enter Pressed");
    }
  };
  
  KeyStroke keystroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false);
  jTextField1.registerKeyboardAction(actionListener, keystroke, JComponent.WHEN_FOCUSED);
  </code></pre>