United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-8010721 [macosx] In JDK7 the menu bar disappears when a Dialog is shown
JDK-8010721 : [macosx] In JDK7 the menu bar disappears when a Dialog is shown

Details
Type:
Bug
Submit Date:
2013-03-25
Status:
Closed
Updated Date:
2013-12-17
Project Name:
JDK
Resolved Date:
2013-05-27
Component:
client-libs
OS:
os_x
Sub-Component:
java.awt
CPU:
generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
7,8
Fixed Versions:

Related Reports
Backport:
Backport:
Backport:
Relates:

Sub Tasks

Description
Unlike Apple JDK, JDK7 removes the menu bar when a Dialog is shown.
                                    

Comments
The following test will work differently on Apple and Oracle JDK:

import com.apple.laf.AquaLookAndFeel;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.reflect.InvocationTargetException;

public class test extends JFrame {

    test() {
        super();

        try {
            UIManager.setLookAndFeel(new AquaLookAndFeel());
        } catch (UnsupportedLookAndFeelException e) {
            e.printStackTrace();
        }

        JMenu menu = new JMenu("menu 1");
        menu.add(new JMenuItem("menu item 1"));
        menu.add(new JMenuItem("menu item 2"));

        JMenu menu2 = new JMenu("menu 2");
        menu2.add("menu item 1");
        menu2.add("menu item 2");

        JMenuBar bar = new JMenuBar();
        bar.add(menu);
        bar.add(menu2);

        setJMenuBar(bar);

        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        JButton btn = new JButton("test");
        btn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JDialog dialog = new JDialog(test.this, "test dialog");
                //dialog.setModal(true);
                dialog.setSize(100, 100);
                dialog.setLocation(300, 300);
                dialog.setVisible(true);
            }
        });
        add(btn, BorderLayout.SOUTH);

        setSize(300, 300);
        pack();
    }

    public static void main(String[] args) {
        try {
            System.setProperty("apple.laf.useScreenMenuBar", String.valueOf(Boolean.TRUE));
            SwingUtilities.invokeAndWait(new Runnable() {
                @Override
                public void run() {
                    test t = new test();
                    t.setVisible(true);
                }
            });
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}

Under Apple JDK the test will leave the menu bar intact. Under Oracle JDK, however, the test will remove menu bar contents.

Please note the commented line. When displaying a modal dialog, Apple JDK will leave frame menu bar intact, but will disable its contents. Oracle JDK will remove menu bar contents.
                                     
2013-03-25
URL:   http://hg.openjdk.java.net/jdk8/awt/jdk/rev/c36626831f07
User:  mcherkas
Date:  2013-05-27 08:51:36 +0000

                                     
2013-05-27
URL:   http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/c36626831f07
User:  lana
Date:  2013-06-04 17:27:56 +0000

                                     
2013-06-04
The fix doesn't contain a regression test because testing would require manual interaction and is applicable to Mac OS X only.
                                     
2013-06-05
fix verified with b93
                                     
2013-07-12
AWT_Menu/Manual/MacMenuBarTest
                                     
2013-07-17



Hardware and Software, Engineered to Work Together