changeset 44768:0d302a56785d

8177919: java.awt.Desktop.setDefaultMenuBar?() should be specified to throw IllegalStateException Reviewed-by: serb, prr
author azvegint
date Mon, 17 Apr 2017 18:44:53 +0300
parents b9860b00ef56
children 04e273dc1722
files jdk/src/java.desktop/macosx/classes/com/apple/eawt/_AppMenuBarHandler.java jdk/src/java.desktop/macosx/classes/com/apple/laf/AquaMenuBarUI.java jdk/src/java.desktop/share/classes/java/awt/Desktop.java jdk/src/java.desktop/share/classes/javax/swing/JRootPane.java
diffstat 4 files changed, 20 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/src/java.desktop/macosx/classes/com/apple/eawt/_AppMenuBarHandler.java	Mon Apr 17 08:37:15 2017 -0700
+++ b/jdk/src/java.desktop/macosx/classes/com/apple/eawt/_AppMenuBarHandler.java	Mon Apr 17 18:44:53 2017 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,9 +25,13 @@
 
 package com.apple.eawt;
 
+import java.awt.Container;
 import java.awt.Frame;
 
-import javax.swing.*;
+
+import javax.swing.JFrame;
+import javax.swing.JLayeredPane;
+import javax.swing.JMenuBar;
 import javax.swing.plaf.MenuBarUI;
 
 import com.apple.laf.ScreenMenuBar;
@@ -102,10 +106,15 @@
             return;
         }
 
-        final MenuBarUI ui = menuBar.getUI();
+        Container parent = menuBar.getParent();
+        if (parent instanceof JLayeredPane) {
+            ((JLayeredPane) parent).remove(menuBar);
+        }
+
+        MenuBarUI ui = menuBar.getUI();
         if (!(ui instanceof AquaMenuBarUI)) {
-            // Aqua was not installed
-            throw new IllegalStateException("Application.setDefaultMenuBar() only works with the Aqua Look and Feel");
+            ui = new AquaMenuBarUI();
+            menuBar.setUI(ui);
         }
 
         final AquaMenuBarUI aquaUI = (AquaMenuBarUI)ui;
--- a/jdk/src/java.desktop/macosx/classes/com/apple/laf/AquaMenuBarUI.java	Mon Apr 17 08:37:15 2017 -0700
+++ b/jdk/src/java.desktop/macosx/classes/com/apple/laf/AquaMenuBarUI.java	Mon Apr 17 18:44:53 2017 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -50,7 +50,7 @@
     public void uninstallUI(final JComponent c) {
         if (fScreenMenuBar != null) {
             final JFrame frame = (JFrame)(c.getTopLevelAncestor());
-            if (frame.getMenuBar() == fScreenMenuBar) {
+            if (frame != null && frame.getMenuBar() == fScreenMenuBar) {
                 frame.setMenuBar((MenuBar)null);
             }
             fScreenMenuBar = null;
--- a/jdk/src/java.desktop/share/classes/java/awt/Desktop.java	Mon Apr 17 08:37:15 2017 -0700
+++ b/jdk/src/java.desktop/share/classes/java/awt/Desktop.java	Mon Apr 17 18:44:53 2017 +0300
@@ -992,8 +992,6 @@
     /**
      * Sets the default menu bar to use when there are no active frames.
      *
-     * @implNote Aqua Look and Feel should be active to support this on Mac OS.
-     *
      * @param menuBar to use when no other frames are active
      * @throws SecurityException if a security manager exists and it denies the
      * {@code RuntimePermission("canProcessApplicationEvents")} permission.
--- a/jdk/src/java.desktop/share/classes/javax/swing/JRootPane.java	Mon Apr 17 08:37:15 2017 -0700
+++ b/jdk/src/java.desktop/share/classes/javax/swing/JRootPane.java	Mon Apr 17 18:44:53 2017 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -541,8 +541,10 @@
             layeredPane.remove(menuBar);
         menuBar = menu;
 
-        if(menuBar != null)
+        if(menuBar != null) {
+            menuBar.updateUI();
             layeredPane.add(menuBar, JLayeredPane.FRAME_CONTENT_LAYER);
+        }
     }
 
     /**