Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5044826

Inactive window receiving key events, active window not receiving key events

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.2
    • client-libs



      Name: gm110360 Date: 05/10/2004


      FULL PRODUCT VERSION :
      java version "1.4.2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
      Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)

      FULL OS VERSION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      When a modal dialog is opened from a non-modal frame, key events are not sent to the modal dialog, they are instead sent to the inactive frame.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Run attached program.
      2) Click the button labeled "Open second screen"
      3) A dialog with a single button will appear
      4) Try hitting the Enter key to trigger the default action - the Enter key is sent back to the inactive window
      5) Try hitting the hot key combination for the button - this, too, is sent back to the inactive window
      6) Try hitting the hot key combinations for the buttons on the first window - they work even though that window is not active


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      KeyEvents will go to the active window
      ACTUAL -
      KeyEvents go to the inactive window

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;

      public class TestFrame
      {
          public static void main(String[] args) throws Exception
          {
              JButton firstFrameDefaultButton = new JButton();
              firstFrameDefaultButton.setText("Default");
              firstFrameDefaultButton.setMnemonic('D');
              firstFrameDefaultButton.addActionListener(new ActionListener()
              {
                  public void actionPerformed(ActionEvent e)
                  {
                      System.out.println("Default button on first frame");
                  }
              });
              JButton openSecond = new JButton();
              openSecond.setText("Open second");
              openSecond.setMnemonic('O');

              final JFrame firstFrame = new JFrame();
              firstFrame.setTitle("First frame");
              firstFrame.setSize(200, 100);
              firstFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              firstFrame.getRootPane().setDefaultButton(firstFrameDefaultButton);
              firstFrame.getContentPane().setLayout(new FlowLayout());
              firstFrame.getContentPane().add(firstFrameDefaultButton, null);
              firstFrame.getContentPane().add(openSecond, null);

              openSecond.addActionListener(new java.awt.event.ActionListener()
              {
                  public void actionPerformed(ActionEvent e)
                  {
                      JButton secondFrameDefaultButton = new JButton();
                      secondFrameDefaultButton.setFocusable(false);
                      secondFrameDefaultButton.setText("Click");
                      secondFrameDefaultButton.setMnemonic('C');
                      secondFrameDefaultButton.addActionListener(new ActionListener()
                      {
                          public void actionPerformed(ActionEvent e)
                          {
                              System.out.println("Default button on second frame");
                          }
                      });

                      JDialog secondFrame = new JDialog(firstFrame, true);
                      secondFrame.setTitle("Second frame");
                      secondFrame.setSize(200, 100);
                      secondFrame.setLocation(100, 100);
                      secondFrame.getContentPane().setLayout(new FlowLayout());
                      secondFrame.getRootPane().setDefaultButton(secondFrameDefaultButton);
                      secondFrame.getContentPane().add(secondFrameDefaultButton);
                      secondFrame.setVisible(true);
                  }
              });

              firstFrame.show();
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      If the button on the modal dialog is focusable, this problem won't occur.
      (Incident Review ID: 200494)
      ======================================================================

            shickeysunw Shannon Hickey (Inactive)
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: