JDK-8012634 : [macosx] Mac OS Screen Menubar disappears after one JFrame window is closed (disposed)
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7u17
  • Priority: P3
  • Status: Resolved
  • Resolution: Duplicate
  • OS: os_x
  • Submitted: 2013-04-16
  • Updated: 2013-04-18
  • Resolved: 2013-04-18
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
Oracle JDK 1.7

 " Java -version "  =
Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

 " javac -version "  =
javac 1.7.0_17

ADDITIONAL OS VERSION INFORMATION :
Mac OS 10.7.5 (Lion)

 " uname -a "  =
Darwin Zeus.local 11.4.2 Darwin Kernel Version 11.4.2: Thu Aug 23 16:25:48 PDT 2012; root:xnu-1699.32.7~1/RELEASE_X86_64 x86_64


A DESCRIPTION OF THE PROBLEM :
While running a multi-window Swing application on Mac OS, and using the Java Runtime property  " -Dapple.laf.useScreenMenuBar=true " , closing one of the JFrame windows  will cause the screen menubar to disappear, even though the application still has open windows.

I did some testing, and it seems that dispose() is the key.  This behavior happens when dispose() is called on the JFrame.

This behavior was observed after upgrading from JDK 1.6 (Apple) to JDK 1.7 (Oracle).

REGRESSION.  Last worked in version 6u31

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Using MenuTest.java included below:

1. javac MenuTest.java

2. Run MenuTest as follows:
java  -Dapple.laf.useScreenMenuBar=true MenuTest

MenuTest will open two JFrame windows, with a Mac OS screen menubar.

3. Close one of the windows with the mouse, the screen menubar will disappear.

4. Iconify the remaining window, and then de-iconify the window.  The screen menubar will re-appear.



EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The screen menubar should remain visible while the application is active has open windows.
ACTUAL -
The screen menubar disappears when any window is closed using dispose().

ERROR MESSAGES/STACK TRACES THAT OCCUR :
no error messages

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
/**
 * Michael Wright - Simple menu test for Java 1.7 on Mac OS X
 *                  Demonstrates screen menubar bug.
 */

import java.awt.*;
import javax.swing.*;

public class MenuTest extends JFrame {
    public MenuTest(int x, int y) {
        menuBar1 = new JMenuBar();

        menu1 = new JMenu();
        menuItem1 = new JMenuItem();
        menu2 = new JMenu();
        menuItem2 = new JMenuItem();

        Container contentPane = getContentPane();
        contentPane.setLayout(null);

        menu1.setText( " File " );
        menuItem1.setText( " Exit " );
        menu1.add(menuItem1);
        menuBar1.add(menu1);

        menu2.setText( " Menu 2 " );
        menuItem2.setText( " Do Nothing " );
        menu2.add(menuItem2);

        menuBar1.add(menu2);
        setJMenuBar(menuBar1);
        
        // Following will cause ScreenMenubar to disappear on Mac OS with JSE 1.7
        this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        
        setBounds(x, y, 500, 400);
        this.setVisible( true );
    }

    private JMenuBar menuBar1;
    private JMenu menu1;
    private JMenuItem menuItem1;
    private JMenu menu2;
    private JMenuItem menuItem2;
    
    public static void main (String[] args ) {
        new MenuTest(10, 10);
        new MenuTest(50, 50);
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
In my production application, I have a window listener for the WIndowClosing event, and my workaround is to change:

this.dispose();

  -- to --

this.setVisible( false );

This is a poor workaround because it doesn't release the JFrame resources, but allows me to continue development.