--- old/src/java.desktop/share/classes/javax/swing/JMenuBar.java 2016-11-29 15:07:51.000000000 +0300 +++ new/src/java.desktop/share/classes/javax/swing/JMenuBar.java 2016-11-29 15:07:51.000000000 +0300 @@ -37,10 +37,15 @@ import java.io.ObjectOutputStream; import java.io.ObjectInputStream; import java.io.IOException; +import java.lang.reflect.Method; import javax.swing.plaf.*; import javax.accessibility.*; +import java.security.AccessController; +import java.security.PrivilegedAction; +import sun.awt.OSInfo; + /** * An implementation of a menu bar. You add JMenu objects to the * menu bar to construct a menu. When the user selects a JMenu @@ -106,6 +111,36 @@ private static final boolean VERBOSE = false; // show reuse hits/misses private static final boolean DEBUG = false; // show bad params, misc. + private static boolean disableGlobalMenuBar = true; + + + static { + AccessController + .doPrivileged((PrivilegedAction) () -> { + if (OSInfo.getOSType() == OSInfo.OSType.MACOSX + && !Boolean.getBoolean("jdk.swing.disableForcedGlobalMenuBar")) { + System.loadLibrary("osxui"); + disableGlobalMenuBar = false; + } + return null; + }); + } + + + private static boolean getScreenMenuBarProperty() { + try { + Class cls = Class.forName("com.apple.laf.AquaMenuBarUI"); + Method m = cls.getDeclaredMethod("getScreenMenuBarProperty"); + m.setAccessible(true); + + return ((boolean) m.invoke(null)); + } catch (Exception ignored) {} + + return false; + } + + + /** * Creates a new menu bar. */ @@ -144,6 +179,13 @@ * @see JComponent#updateUI */ public void updateUI() { + if (!disableGlobalMenuBar) { + if (getScreenMenuBarProperty()) { + UIManager.put("MenuBarUI", "com.apple.laf.AquaMenuBarUI"); + } else { + UIManager.put("MenuBarUI", null); + } + } setUI((MenuBarUI)UIManager.getUI(this)); }