8177919: java.awt.Desktop.setDefaultMenuBar() should be specified to throw IllegalStateException
Reviewed-by: serb, prr
This commit is contained in:
parent
90161fc0b3
commit
c43268c3cb
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -25,9 +25,13 @@
|
|||||||
|
|
||||||
package com.apple.eawt;
|
package com.apple.eawt;
|
||||||
|
|
||||||
|
import java.awt.Container;
|
||||||
import java.awt.Frame;
|
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 javax.swing.plaf.MenuBarUI;
|
||||||
|
|
||||||
import com.apple.laf.ScreenMenuBar;
|
import com.apple.laf.ScreenMenuBar;
|
||||||
@ -102,10 +106,15 @@ class _AppMenuBarHandler {
|
|||||||
return;
|
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)) {
|
if (!(ui instanceof AquaMenuBarUI)) {
|
||||||
// Aqua was not installed
|
ui = new AquaMenuBarUI();
|
||||||
throw new IllegalStateException("Application.setDefaultMenuBar() only works with the Aqua Look and Feel");
|
menuBar.setUI(ui);
|
||||||
}
|
}
|
||||||
|
|
||||||
final AquaMenuBarUI aquaUI = (AquaMenuBarUI)ui;
|
final AquaMenuBarUI aquaUI = (AquaMenuBarUI)ui;
|
||||||
|
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -50,7 +50,7 @@ public class AquaMenuBarUI extends BasicMenuBarUI implements ScreenMenuBarProvid
|
|||||||
public void uninstallUI(final JComponent c) {
|
public void uninstallUI(final JComponent c) {
|
||||||
if (fScreenMenuBar != null) {
|
if (fScreenMenuBar != null) {
|
||||||
final JFrame frame = (JFrame)(c.getTopLevelAncestor());
|
final JFrame frame = (JFrame)(c.getTopLevelAncestor());
|
||||||
if (frame.getMenuBar() == fScreenMenuBar) {
|
if (frame != null && frame.getMenuBar() == fScreenMenuBar) {
|
||||||
frame.setMenuBar((MenuBar)null);
|
frame.setMenuBar((MenuBar)null);
|
||||||
}
|
}
|
||||||
fScreenMenuBar = null;
|
fScreenMenuBar = null;
|
||||||
|
@ -992,8 +992,6 @@ public class Desktop {
|
|||||||
/**
|
/**
|
||||||
* Sets the default menu bar to use when there are no active frames.
|
* 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
|
* @param menuBar to use when no other frames are active
|
||||||
* @throws SecurityException if a security manager exists and it denies the
|
* @throws SecurityException if a security manager exists and it denies the
|
||||||
* {@code RuntimePermission("canProcessApplicationEvents")} permission.
|
* {@code RuntimePermission("canProcessApplicationEvents")} permission.
|
||||||
|
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -541,9 +541,11 @@ public class JRootPane extends JComponent implements Accessible {
|
|||||||
layeredPane.remove(menuBar);
|
layeredPane.remove(menuBar);
|
||||||
menuBar = menu;
|
menuBar = menu;
|
||||||
|
|
||||||
if(menuBar != null)
|
if(menuBar != null) {
|
||||||
|
menuBar.updateUI();
|
||||||
layeredPane.add(menuBar, JLayeredPane.FRAME_CONTENT_LAYER);
|
layeredPane.add(menuBar, JLayeredPane.FRAME_CONTENT_LAYER);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the menu bar value.
|
* Specifies the menu bar value.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user