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

Wrong window activated when a modal dialog with null owner is closed

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_xp

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0"
      Java(TM) SE Runtime Environment (build 1.6.0-b105)
      Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      When multiple JFrames are displayed, and a modal dialog with null parent is brought up and disposed, the last created JFrame gets activated.

      Instead the last activated JFrame should be reactivated, which is the behavior for JDK pre 1.6, and JDK 1.6 on Linux and Solaris.

      The cause of the problem seems to be that the WINDOW_ACTIVATED WindowEvent, generated in a native method in Sun's WToolkit, always has the source as the last created JFrame.

      There seems to be several related bugs that have been fixed. Since this only happens in Windows JDK6, it seems like a regression.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the test code, which brings up 4 identical JFrames with a button inside that brings up a modal dialog.

      Only the modal dialog in the 3rd window (titled 2) has owner set to be that window.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Click the button in each window, and click OK. The window should be reactivated.
      ACTUAL -
      If the dialog is brought up from window 0, 1, and 4, window 4 is reactivated.

      If the dialog is brought up from window 3, window 3 is correctly reactivated.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.EventQueue;
      import java.awt.event.*;

      import javax.swing.*;

      public class TestJFrameFocus extends JFrame
      {
          public TestJFrameFocus(String title, int x, int y, int width, int height, final boolean setOwner)
          {
              super(title);
              
              JButton but = new JButton("Show dialog box");
              but.addActionListener(new ActionListener()
              {
                  public void actionPerformed(ActionEvent e)
                  {
                      JOptionPane.showMessageDialog(setOwner ? TestJFrameFocus.this : null, "Blah");
                  }
              });
              getContentPane().add(but);
              
              addWindowListener(new WindowAdapter()
              {
                  public void windowActivated(WindowEvent event)
                  {
                      System.out.println("Activated: " + getTitle() + ", source " + event.getSource());
                  }
              });
              
              setSize(width, height);
              setLocation(x, y);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              setVisible(true);
          }
          
          public static void main(String s[])
          {
              EventQueue.invokeLater(new Runnable()
              {
                  public void run()
                  {
                      new TestJFrameFocus("0", 0, 0, 200, 100, false);
                      new TestJFrameFocus("1", 200, 0, 200, 100, false);
                      new TestJFrameFocus("2", 400, 0, 200, 100, true);
                      new TestJFrameFocus("3", 600, 0, 200, 100, false);
                  }
              });
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Always set the owner for modal dialog to be the last activated window, or the window you want to be activated when the dialog is disposed.

      However that may not always be possible.

      Release Regression From : 6
      The above release value was the last known release where this
      bug was not reproducible. Since then there has been a regression.

        Attachments

          Activity

            People

            • Assignee:
              art Artem Ananiev
              Reporter:
              igor Igor Nekrestyanov (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: