Path: blob/master/test/jdk/javax/swing/JRootPane/SilenceOfDeprecatedMenuBar/SilenceOfDeprecatedMenuBar.java
41154 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import javax.swing.JFrame;24import javax.swing.JMenuBar;25import javax.swing.JRootPane;26import javax.swing.SwingUtilities;27import javax.swing.UIManager;28import javax.swing.UnsupportedLookAndFeelException;2930import static javax.swing.UIManager.getInstalledLookAndFeels;3132/**33* @test34* @key headful35* @bug 636832136* @author Sergey Bylokhov37*/38public final class SilenceOfDeprecatedMenuBar implements Runnable {3940public static void main(final String[] args) throws Exception {41for (final UIManager.LookAndFeelInfo laf : getInstalledLookAndFeels()) {42SwingUtilities.invokeAndWait(() -> setLookAndFeel(laf));43SwingUtilities.invokeAndWait(new SilenceOfDeprecatedMenuBar());44}45}4647@Override48public void run() {49final JFrame frame = new DeprecatedFrame();50try {51final JMenuBar bar = new JMenuBar();52frame.setJMenuBar(bar);53frame.setBounds(100, 100, 100, 100);54frame.setLocationRelativeTo(null);55frame.setVisible(true);56if (bar != frame.getJMenuBar()) {57throw new RuntimeException("Wrong JMenuBar");58}59} finally {60frame.dispose();61}62}6364private static void setLookAndFeel(final UIManager.LookAndFeelInfo laf) {65try {66UIManager.setLookAndFeel(laf.getClassName());67System.out.println("LookAndFeel: " + laf.getClassName());68} catch (ClassNotFoundException | InstantiationException |69UnsupportedLookAndFeelException | IllegalAccessException e) {70throw new RuntimeException(e);71}72}7374private static class DeprecatedFrame extends JFrame {7576@Override77protected JRootPane createRootPane() {78return new JRootPane() {79@Override80public JMenuBar getMenuBar() {81throw new RuntimeException("Should not be here");82}83@Override84public void setMenuBar(final JMenuBar menu) {85throw new RuntimeException("Should not be here");86}87};88}89}90}919293