< prev index next >
src/java.desktop/share/classes/javax/swing/JMenuBar.java
Print this page
*** 35,48 ****
--- 35,53 ----
import java.io.Serializable;
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 <code>JMenu</code> objects to the
* menu bar to construct a menu. When the user selects a <code>JMenu</code>
* object, its associated <code>JPopupMenu</code> is displayed, allowing the
* user to select one of the <code>JMenuItems</code> on it.
*** 104,113 ****
--- 109,148 ----
/* diagnostic aids -- should be false for production builds. */
private static final boolean TRACE = false; // trace creates and disposes
private static final boolean VERBOSE = false; // show reuse hits/misses
private static final boolean DEBUG = false; // show bad params, misc.
+ private static boolean disableAquaMenuBarUI = true;
+
+
+ static {
+ AccessController
+ .doPrivileged((PrivilegedAction<Void>) () -> {
+ if (OSInfo.getOSType() == OSInfo.OSType.MACOSX
+ && !Boolean.getBoolean("apple.laf.disableForcedScreenMenuBar")) {
+ System.loadLibrary("osxui");
+ disableAquaMenuBarUI = 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.
*/
public JMenuBar() {
super();
*** 142,151 ****
--- 177,193 ----
* Resets the UI property with a value from the current look and feel.
*
* @see JComponent#updateUI
*/
public void updateUI() {
+ if (!disableAquaMenuBarUI) {
+ if (getScreenMenuBarProperty()) {
+ UIManager.put("MenuBarUI", "com.apple.laf.AquaMenuBarUI");
+ } else {
+ UIManager.put("MenuBarUI", null);
+ }
+ }
setUI((MenuBarUI)UIManager.getUI(this));
}
/**
< prev index next >