SilenceOfDeprecatedMenuBar.java revision 15235:fe58d505fffd
19313Ssos/* 29313Ssos * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 39313Ssos * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 49313Ssos * 59313Ssos * This code is free software; you can redistribute it and/or modify it 69313Ssos * under the terms of the GNU General Public License version 2 only, as 79313Ssos * published by the Free Software Foundation. 89313Ssos * 99313Ssos * This code is distributed in the hope that it will be useful, but WITHOUT 109313Ssos * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 119313Ssos * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 129313Ssos * version 2 for more details (a copy is included in the LICENSE file that 139313Ssos * accompanied this code). 149313Ssos * 159313Ssos * You should have received a copy of the GNU General Public License version 169313Ssos * 2 along with this work; if not, write to the Free Software Foundation, 179313Ssos * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 189313Ssos * 199313Ssos * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 209313Ssos * or visit www.oracle.com if you need additional information or have any 219313Ssos * questions. 229313Ssos */ 239313Ssos 249313Ssosimport javax.swing.JFrame; 259313Ssosimport javax.swing.JMenuBar; 269313Ssosimport javax.swing.JRootPane; 279313Ssosimport javax.swing.SwingUtilities; 2839978Sjfieberimport javax.swing.UIManager; 299313Ssosimport javax.swing.UnsupportedLookAndFeelException; 309313Ssos 3131784Seivindimport static javax.swing.UIManager.getInstalledLookAndFeels; 3231784Seivind 339313Ssos/** 349313Ssos * @test 3512458Sbde * @key headful 369313Ssos * @bug 6368321 379313Ssos * @author Sergey Bylokhov 389313Ssos */ 3931561Sbdepublic final class SilenceOfDeprecatedMenuBar implements Runnable { 409313Ssos 419313Ssos public static void main(final String[] args) throws Exception { 429313Ssos for (final UIManager.LookAndFeelInfo laf : getInstalledLookAndFeels()) { 439313Ssos SwingUtilities.invokeAndWait(() -> setLookAndFeel(laf)); 4414331Speter SwingUtilities.invokeAndWait(new SilenceOfDeprecatedMenuBar()); 4514331Speter } 4612458Sbde } 4712458Sbde 4814331Speter @Override 4914331Speter public void run() { 509313Ssos final JFrame frame = new DeprecatedFrame(); 519313Ssos try { 5230994Sphk final JMenuBar bar = new JMenuBar(); 539313Ssos frame.setJMenuBar(bar); 5412858Speter frame.setBounds(100, 100, 100, 100); 559313Ssos frame.setLocationRelativeTo(null); 569313Ssos frame.setVisible(true); 579313Ssos if (bar != frame.getJMenuBar()) { 5812858Speter throw new RuntimeException("Wrong JMenuBar"); 5914331Speter } 609313Ssos } finally { 6114331Speter frame.dispose(); 6214331Speter } 6314331Speter } 649313Ssos 659313Ssos private static void setLookAndFeel(final UIManager.LookAndFeelInfo laf) { 669313Ssos try { 679313Ssos UIManager.setLookAndFeel(laf.getClassName()); 689313Ssos System.out.println("LookAndFeel: " + laf.getClassName()); 699313Ssos } catch (ClassNotFoundException | InstantiationException | 709313Ssos UnsupportedLookAndFeelException | IllegalAccessException e) { 7130994Sphk throw new RuntimeException(e); 729313Ssos } 739313Ssos } 749313Ssos 7530994Sphk private static class DeprecatedFrame extends JFrame { 769313Ssos 7712858Speter @Override 789313Ssos protected JRootPane createRootPane() { 799313Ssos return new JRootPane() { 809313Ssos @Override 8112858Speter public JMenuBar getMenuBar() { 829313Ssos throw new RuntimeException("Should not be here"); 8314331Speter } 8414331Speter @Override 8514331Speter public void setMenuBar(final JMenuBar menu) { 869313Ssos throw new RuntimeException("Should not be here"); 8714331Speter } 8814331Speter }; 8914331Speter } 9014331Speter } 9114331Speter} 929313Ssos