title: Detecting when user presses enter in Java
body: <p>I have a subclass of JComboBox. I attempt to add a key listener with the following code.</p>
  
  <pre>
  <code>
          addKeyListener(new KeyAdapter() 
          {
              public void keyPressed(KeyEvent evt)
              {
                  if(evt.getKeyCode() == KeyEvent.VK_ENTER)
                  {
                      System.out.println("Pressed");
                  }
              }
          });
  </code>
  </pre>
  
  <p>This however does not correctly detect when the user presses a key. It is actually not called at all. Am I adding this listener wrong? Are there other ways to add it?</p>