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

[macosx] Menubar not correctly updated when JFrame is closed

    XMLWordPrintable

Details

    • x86
    • os_x

    Description

      FULL PRODUCT VERSION :
      java version "1.7.0_09"
      Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
      Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      12.2.0 Darwin Kernel Version 12.2.0: Sat Aug 25 00:48:52 PDT 2012; root:xnu-2050.18.24~1/RELEASE_X86_64 x86_64

      A DESCRIPTION OF THE PROBLEM :
      When having several JFrame's open on Mac OS X, each one having their own JMenuBar. When closing a JFrame, the menubar for the new JFrame in front is not shown

      REGRESSION. Regression from Apple's Java 6uX

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Launch the attached code snippet and follow the instructions in the window "Frame 2"

      2) Close the "Frame 2" window and notice that the menubar is not showing the menubar for "Frame 1".


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The menubar for "Frame 1" should be visible after closing "Frame 2"
      ACTUAL -
      The menubar for "Frame 1" is not visible after closing "Frame 2"

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.BorderLayout;
      import java.awt.Point;

      import javax.swing.JFrame;
      import javax.swing.JLabel;
      import javax.swing.JMenu;
      import javax.swing.JMenuBar;
      import javax.swing.JMenuItem;
      import javax.swing.JPanel;
      import javax.swing.JSeparator;
      import javax.swing.JTextArea;
      import javax.swing.SwingConstants;
      import javax.swing.SwingUtilities;
      import javax.swing.WindowConstants;
      import javax.swing.border.CompoundBorder;
      import javax.swing.border.EmptyBorder;

      public class MWindowClosingBugReport {
        private static JMenu createJMenu(final String menuTitle, final String... menuItemTitles) {
          final JMenu menu = new JMenu(menuTitle);

          for (final String menuItemTitle : menuItemTitles) {
            if (menuItemTitle.equals("-")) {
              menu.add(new JSeparator());
            } else {
              menu.add(new JMenuItem(menuItemTitle));
            }
          }
          
          return menu;
        }
        
        private static JMenuBar createJMenuBar(final String frameTitle) {
          final JMenuBar menuBar = new JMenuBar();
          
          menuBar.add(createJMenu("File", "Open", "Close", "-", "Print..."));
          menuBar.add(createJMenu("Edit", "Undo", "-", "Cut", "Copy", "Paste", "-", "Select All"));
          menuBar.add(createJMenu("MenuBar for " + frameTitle, "The only menu item"));
          
          return menuBar;
        }
        
        private static JFrame createFrame(final String frameTitle) {
          final JFrame frame = new JFrame(frameTitle);
          
          frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
          frame.setJMenuBar(createJMenuBar(frameTitle));
          
          return frame;
        }
        
        private static JFrame createAndShowFrame(final String frameTitle, final JFrame relativeToFrame, final String frameText) {
          final JFrame frame = createFrame(frameTitle);
          
          final JPanel panel = new JPanel();
          panel.setBorder(new CompoundBorder(panel.getBorder(), new EmptyBorder(10, 10, 10, 10)));
          panel.setLayout(new BorderLayout());
          
          final JLabel label = new JLabel("This is " + frameTitle, SwingConstants.CENTER);
          label.setFont(label.getFont().deriveFont(24.0f));
          label.setBorder(new CompoundBorder(new EmptyBorder(10, 10, 10, 10), label.getBorder()));
          
          panel.add(label, BorderLayout.NORTH);
          
          if (frameText != null) {
            final JTextArea textArea = new JTextArea(frameText);
            textArea.setEditable(false);
            textArea.setOpaque(false);
            
            panel.add(textArea, BorderLayout.CENTER);
          }
          
          frame.add(panel);
          
          frame.pack();
          frame.setLocationRelativeTo(relativeToFrame);
          
          if (relativeToFrame != null) {
            final Point location = frame.getLocation();
            frame.setLocation(location.x, location.y + 70);
          }
          
          frame.setVisible(true);
          
          return frame;
        }
        
        public static void main(final String[] args) {
          System.setProperty("apple.laf.useScreenMenuBar", "true");
          
          SwingUtilities.invokeLater(new Runnable() {
            public void run() {
              final JFrame frame1 = createAndShowFrame("Frame 1", null, null);
              
              final JFrame frame2 =
                createAndShowFrame
                  ( "Frame 2",
                    frame1,
                    "Close 'Frame 2' and note that after 'Frame 2' has closed\n" +
                    "the menubar area do not show the menubar for 'Frame 1'. You\n" +
                    "need to activate and deactivate this application to see the\n" +
                    "menubar for 'Frame 1'. E.g. use cmd-Tab to navigate away from\n" +
                    "this application and back again");
            }
          });
        }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      No known workaround

      Attachments

        Issue Links

          Activity

            People

              leonidr Leonid Romanov (Inactive)
              rlewis Roger Lewis (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: