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

Wrong dialog on top with multiple modal dialogs

    Details

    • Subcomponent:
    • Introduced In Version:
    • CPU:
      x86_64
    • OS:
      os_x

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_131"
      Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
      Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Mac OS Sierra 10.12.4
      uname -a output:
      Darwin Jessicas-MBP.biomatters.com 16.5.0 Darwin Kernel Version 16.5.0: Fri Mar 3 16:52:33 PST 2017; root:xnu-3789.51.2~3/RELEASE_X86_64 x86_64

      A DESCRIPTION OF THE PROBLEM :
      When a modal dialog (A) creates a new modal dialog (B), sometimes dialog (A) appears on top of dialog (B), even though (B) has focus. When another application window is clicked (grabbing focus), the modal dialogs still appear on top. The behaviour seems to depend on whether the user attempts to click the main window before opening dialog (B).

      This bug also existed in Java 8u121:
      java version "1.8.0_121"
      Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)


      REGRESSION. Last worked in version 8u112

      ADDITIONAL REGRESSION INFORMATION:
      java version "1.8.0_112"
      Java(TM) SE Runtime Environment (build 1.8.0_112-b16)
      Java HotSpot(TM) 64-Bit Server VM (build 25.112-b16, mixed mode)


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Launch application Main
      2. Create a dialog by clicking "Press the button". Move the new dialog a bit so that you'll be able to see the next dialog.
      3. Click the main window (with the title "This is a frame"). The dialog "This is a dialog 1" will retain focus.
      4. Click the "Open a new modal dialog" button.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      New dialog ("This is a dialog 2") should appear on top of the older dialog ("This is a dialog 1")
      ACTUAL -
      "This is a dialog 2" appears behind "This is a dialog 1". Windows from other applications appear underneath "This is a dialog 1" if they grab focus.

      REPRODUCIBILITY :
      This bug can be reproduced always.

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

      public class Main extends JFrame {
          MyPanel panel;

          public Main() {
              setTitle("This is a frame");
              setSize(300, 200);
              panel = new MyPanel(this);
              add(panel);

              setLocationRelativeTo(null);
              setDefaultCloseOperation(EXIT_ON_CLOSE);
          }

          public static void main(String[] args) {
              EventQueue.invokeLater(() -> {
                  Main frame = new Main();
                  frame.pack();
                  frame.setVisible(true);
              });
          }

          private static class MyPanel extends JPanel {

              int dialogCounter = 1;

              public MyPanel(JFrame parent) {
                  super();
                  setPreferredSize(new Dimension(300, 200));
                  JButton button = new JButton("Press the button");
                  button.addActionListener(e -> showDialog(parent));

                  add(button);
              }

              private void showDialog(Frame parent) {
                  JDialog dialog = new JDialog(parent, "This is dialog " + dialogCounter, true);
                  setupDialog(dialog);
              }

              private void showDialog(Dialog parent) {
                  JDialog dialog = new JDialog(parent, "This is dialog " + dialogCounter, true);
                  setupDialog(dialog);
              }

              private void setupDialog(JDialog dialog) {
                  JPanel dialogPanel = new JPanel();
                  dialogPanel.setPreferredSize(new Dimension(300, 200));
                  dialogPanel.add(new JLabel("Current dialog count: " + dialogCounter++));
                  JButton button = new JButton("Open a new modal dialog");
                  button.addActionListener(e -> showDialog(dialog));
                  dialogPanel.add(button);
                  dialog.add(dialogPanel);
                  dialog.pack();
                  dialog.setVisible(true);
              }
          }
      }



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

        Attachments

          Activity

            People

            • Assignee:
              pardesha Pardeep Sharma
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: