title: Why isn't the JDialog triggering the key listener's keyPressed method?
body: <p>This is my code </p>
  
  <pre><code> JToolBar customizeKeys = new JToolBar();
   customizeKeys.add(new ChangeKeyListen("left"));
   private class ChangeKeyListen extends AbstractAction{
      private JDialog myDialog;
      class KeyGetter extends KeyAdapter {
          @Override
          public void keyPressed(KeyEvent e) {
              super.keyPressed(e);
              OtherPanel.this.map(
                          KeyEvent.getKeyText(e.getKeyCode()),
                                              keyAction);
              myDialog.setVisible(false);
              myDialog.removeKeyListener(getKeyListeners()[0]);
          }
      };
      public ChangeKeyListen(String name) {
          super(name);
      }
      @Override
      public void actionPerformed(ActionEvent e) {
         myDialog = new JOptionPane().createDialog("Press a key");
         myDialog.setVisible(true);
         myDialog.requestFocusInWindow();
         System.out.println(myDialog.getFocusableWindowState());
         myDialog.addKeyListener(new KeyGetter());
         System.out.println( myDialog.getKeyListeners());
       }
  }
  </code></pre>
  
  <p>What I am trying to do here is when the user clicks the JButton that was added to the JToolBar with the attributes of its action, the user will be prompted with my own customized dialog box. The user can then press any key to close the dialog box.(it actually just be invisible). When I run the application, everything looks fine. The JToolBar looks right and the button looks right. When I click the button, the correct controller behavior occurs as the dialog box is popped up.(just visible) However the key adapter's keyPressed method isn't being triggered at all when i press a key.</p>
  
  <p>What I've done to debug this is to first make sure that the JDialog can first of all be focusable so it can receive key events from the keyboard. I did that with this line of </p>
  
  <pre><code>System.out.println(myDialog.getFocusableWindowState());
  </code></pre>
  
  <p>and what I got on the console was true. Next I made sure that the key listener was being set. I did that with </p>
  
  <pre><code> System.out.println( myDialog.getKeyListeners());
  </code></pre>
  
  <p>and this printed out </p>
  
  <pre><code>[Ljava.awt.event.KeyListener;@350b914b
  </code></pre>
  
  <p>which I assumed was a correct memory address for an object allocated from the heap.</p>
  
  <p>I then checked out similar threads.</p>
  
  <p>My issue couldn't be <a href="https://stackoverflow.com/questions/6060399/jbutton-listener-isnt-triggered-why">Jbutton listener isn&#39;t triggered, why?</a> because the dialog box showed up and I made sure that the key listener was added with the print key listeners line. 
  I couldn't use what the user said in <a href="https://stackoverflow.com/questions/23002522/trying-to-use-key-listener">Trying to use key Listener</a> because I need to listen for the key press and use that key press later in my program.
  And this doesn't help either <a href="https://stackoverflow.com/questions/22586080/why-wont-this-keyevent-work">Why wont this KeyEvent work?</a> 
  because I need a general reaction to key presses to obtain which key was pressed.</p>
  
  <p>I know that keyPressed isn't being executed because I put a breakpoint inside the method and this print statement</p>
  
  <pre><code>   System.out.println(KeyEvent.getKeyText(e.getKeyCode()));  
  </code></pre>
  
  <p>wasn't printing anything on the console.</p>
  
  <p>Does anyone know how i can fix this issue?</p>