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

Two modal dialogs displayed one after another disable screen menu items

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      All Java versions including the most recent release
      Apple M2
      MacOS Ventura 13.6.5 (22G621)

      A DESCRIPTION OF THE PROBLEM :
      Two modal dialogs displayed one after another disable disable screen menu items.
      I observed this behavior occurred after I updated my OS from 13.6.4 to 13.6.5.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the application below.
      Execute action "Click me" from the menu "Run".
      Observe and confirm 2 confirmation messages by clicking on "Ok".
      After the second message is confirmed, try to access the menu action again.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The menu actions should remain available.
      ACTUAL -
      The menu action is grayed out.

      ---------- BEGIN SOURCE ----------
      import javax.swing.JFrame;
      import javax.swing.JMenu;
      import javax.swing.JMenuBar;
      import javax.swing.JMenuItem;
      import javax.swing.JOptionPane;
      import javax.swing.JLabel;
      import java.awt.BorderLayout;

      public class MainFrame extends JFrame {
          public MainFrame() {
              System.setProperty("apple.laf.useScreenMenuBar", "true");
              this.setSize(300, 200);
              this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              this.setLayout(new BorderLayout());

              // Create menu bar
              JMenuBar menuBar = new JMenuBar();

              // Create a menu
              JMenu runMenu = new JMenu("Run");

              // Create a menu item
              JMenuItem clickMeItem = new JMenuItem("Click me");

              // Add action listener to menu item
              clickMeItem.addActionListener(e -> {
                  JOptionPane.showMessageDialog(this, "The application menu becomes disabled");
                  JOptionPane.showMessageDialog(this, "The application menu remains disabled after the focus goes back to the main frame");
              });

              // Add menu item to menu
              runMenu.add(clickMeItem);

              // Add menu to menu bar
              menuBar.add(runMenu);

              // Set the menu bar
              this.setJMenuBar(menuBar);

              // Add a label to display text in the middle of the frame
              JLabel label = new JLabel("Execute \"Run->Click me\"", JLabel.CENTER);
              this.add(label, BorderLayout.CENTER);
          }

          public static void main(String[] args) {
              javax.swing.SwingUtilities.invokeLater(() -> {
                  MainFrame frame = new MainFrame();
                  frame.setVisible(true);
              });
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      1. The menu is reenabled after user changes to another application and activates this application again.
      2. The menu is reenabled if you add

                  final MenuBar awtMenubar = getMenuBar();
                  setMenuBar(null);
                  setMenuBar(awtMenubar);

      after the second call of JOptionPane.showMessageDialog

      FREQUENCY : always


            psadhukhan Prasanta Sadhukhan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: