30933
|
1 |
/*
|
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
import javax.swing.JFrame;
|
|
25 |
import javax.swing.JMenuBar;
|
|
26 |
import javax.swing.JRootPane;
|
|
27 |
import javax.swing.SwingUtilities;
|
|
28 |
import javax.swing.UIManager;
|
|
29 |
import javax.swing.UnsupportedLookAndFeelException;
|
|
30 |
|
|
31 |
import static javax.swing.UIManager.getInstalledLookAndFeels;
|
|
32 |
|
|
33 |
/**
|
|
34 |
* @test
|
|
35 |
* @bug 6368321
|
|
36 |
* @author Sergey Bylokhov
|
|
37 |
*/
|
|
38 |
public final class SilenceOfDeprecatedMenuBar implements Runnable {
|
|
39 |
|
|
40 |
public static void main(final String[] args) throws Exception {
|
|
41 |
for (final UIManager.LookAndFeelInfo laf : getInstalledLookAndFeels()) {
|
|
42 |
SwingUtilities.invokeAndWait(() -> setLookAndFeel(laf));
|
|
43 |
SwingUtilities.invokeAndWait(new SilenceOfDeprecatedMenuBar());
|
|
44 |
}
|
|
45 |
}
|
|
46 |
|
|
47 |
@Override
|
|
48 |
public void run() {
|
|
49 |
final JFrame frame = new DeprecatedFrame();
|
|
50 |
try {
|
|
51 |
final JMenuBar bar = new JMenuBar();
|
|
52 |
frame.setJMenuBar(bar);
|
|
53 |
frame.setBounds(100, 100, 100, 100);
|
|
54 |
frame.setLocationRelativeTo(null);
|
|
55 |
frame.setVisible(true);
|
|
56 |
if (bar != frame.getJMenuBar()) {
|
|
57 |
throw new RuntimeException("Wrong JMenuBar");
|
|
58 |
}
|
|
59 |
} finally {
|
|
60 |
frame.dispose();
|
|
61 |
}
|
|
62 |
}
|
|
63 |
|
|
64 |
private static void setLookAndFeel(final UIManager.LookAndFeelInfo laf) {
|
|
65 |
try {
|
|
66 |
UIManager.setLookAndFeel(laf.getClassName());
|
|
67 |
System.out.println("LookAndFeel: " + laf.getClassName());
|
|
68 |
} catch (ClassNotFoundException | InstantiationException |
|
|
69 |
UnsupportedLookAndFeelException | IllegalAccessException e) {
|
|
70 |
throw new RuntimeException(e);
|
|
71 |
}
|
|
72 |
}
|
|
73 |
|
|
74 |
private static class DeprecatedFrame extends JFrame {
|
|
75 |
|
|
76 |
@Override
|
|
77 |
protected JRootPane createRootPane() {
|
|
78 |
return new JRootPane() {
|
|
79 |
@Override
|
|
80 |
public JMenuBar getMenuBar() {
|
|
81 |
throw new RuntimeException("Should not be here");
|
|
82 |
}
|
|
83 |
@Override
|
|
84 |
public void setMenuBar(final JMenuBar menu) {
|
|
85 |
throw new RuntimeException("Should not be here");
|
|
86 |
}
|
|
87 |
};
|
|
88 |
}
|
|
89 |
}
|
|
90 |
}
|