FULL PRODUCT VERSION :
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Darwin Alans-iMac 14.5.0 Darwin Kernel Version 14.5.0: Tue Sep 1 21:23:09 PDT 2015; root:xnu-2782.50.1~1/RELEASE_X86_64 x86_64
A DESCRIPTION OF THE PROBLEM :
If the com.apple.eawt.Application.setDefaultMenuBar() method is called while the application is not the active application, the screen menu bar is not initialized -- the specified menu bar items are not displayed on the screen menu bar.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the enclosed test program with -Dapple.laf.useScreenMenuBar=true.
After the test program icon appears in the dock, select it to make the test program the active application.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The Chess.app application should be opened, if necessary, and made the active application. The test application icon should appear in the dock but the application should not be made active. When activated, the screen menu bar should display a File menu.
ACTUAL -
The screen menu bar does not display a File menu.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package test;
import java.io.IOException;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.SwingUtilities;
import com.apple.eawt.Application;
public class Test
{
public Test()
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
Application application = Application.getApplication();
JMenuBar menuBar = new JMenuBar();
menuBar.add(new JMenu("File"));
if (true) {
// Make a different application active when setting the default menu bar
Runtime r = Runtime.getRuntime();
try {
r.exec("/usr/bin/open /Applications/Chess.app");
Thread.sleep(5000);
} catch (IOException ex) {
System.err.println("Unable to open application: " + ex.getMessage());
} catch (InterruptedException ex) {
return;
}
}
application.setDefaultMenuBar(menuBar);
}
});
}
public static void main(String[] args)
{
new Test();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
The problem appears to be the kludgy way that _AppMenuBarHandler().setDefaultMenuBar() attempts to trigger the initialization of the screen menu bar by creating and immediately hiding an invisible Frame. The intent is that the Frame become focused so that -[AWTWindow windowDidResignKey:] will be called when the window is hidden. However, the window will not become focused if another application is active. (To do that, -[NSApplication activateIgnoringOtherApps:] should be used.) If the window does not become focused, then the windowDidResignKey: method is never called, so the screen menu bar is not initialized.
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Darwin Alans-iMac 14.5.0 Darwin Kernel Version 14.5.0: Tue Sep 1 21:23:09 PDT 2015; root:xnu-2782.50.1~1/RELEASE_X86_64 x86_64
A DESCRIPTION OF THE PROBLEM :
If the com.apple.eawt.Application.setDefaultMenuBar() method is called while the application is not the active application, the screen menu bar is not initialized -- the specified menu bar items are not displayed on the screen menu bar.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the enclosed test program with -Dapple.laf.useScreenMenuBar=true.
After the test program icon appears in the dock, select it to make the test program the active application.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The Chess.app application should be opened, if necessary, and made the active application. The test application icon should appear in the dock but the application should not be made active. When activated, the screen menu bar should display a File menu.
ACTUAL -
The screen menu bar does not display a File menu.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package test;
import java.io.IOException;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.SwingUtilities;
import com.apple.eawt.Application;
public class Test
{
public Test()
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
Application application = Application.getApplication();
JMenuBar menuBar = new JMenuBar();
menuBar.add(new JMenu("File"));
if (true) {
// Make a different application active when setting the default menu bar
Runtime r = Runtime.getRuntime();
try {
r.exec("/usr/bin/open /Applications/Chess.app");
Thread.sleep(5000);
} catch (IOException ex) {
System.err.println("Unable to open application: " + ex.getMessage());
} catch (InterruptedException ex) {
return;
}
}
application.setDefaultMenuBar(menuBar);
}
});
}
public static void main(String[] args)
{
new Test();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
The problem appears to be the kludgy way that _AppMenuBarHandler().setDefaultMenuBar() attempts to trigger the initialization of the screen menu bar by creating and immediately hiding an invisible Frame. The intent is that the Frame become focused so that -[AWTWindow windowDidResignKey:] will be called when the window is hidden. However, the window will not become focused if another application is active. (To do that, -[NSApplication activateIgnoringOtherApps:] should be used.) If the window does not become focused, then the windowDidResignKey: method is never called, so the screen menu bar is not initialized.