author | hseigel |
Wed, 01 Mar 2017 08:00:02 -0500 | |
changeset 46194 | 5596e6f63072 |
parent 32669 | 8ff453aa551b |
child 46151 | 5fa789776f7d |
permissions | -rw-r--r-- |
32669
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
1 |
/* |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
4 |
* |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
8 |
* |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
13 |
* accompanied this code). |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
14 |
* |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
18 |
* |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
21 |
* questions. |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
22 |
*/ |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
23 |
|
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
24 |
import java.awt.EventQueue; |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
25 |
import java.awt.FlowLayout; |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
26 |
|
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
27 |
import javax.swing.*; |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
28 |
import javax.swing.UIManager.LookAndFeelInfo; |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
29 |
|
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
30 |
import static javax.swing.UIManager.getInstalledLookAndFeels; |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
31 |
|
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
32 |
/** |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
33 |
* @test |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
34 |
* @bug 8134947 |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
35 |
* @author Sergey Bylokhov |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
36 |
* @run main/timeout=300/othervm -Xmx12m -XX:+HeapDumpOnOutOfMemoryError UnninstallUIMemoryLeaks |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
37 |
*/ |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
38 |
public final class UnninstallUIMemoryLeaks { |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
39 |
|
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
40 |
private static JFrame frame; |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
41 |
|
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
42 |
public static void main(final String[] args) throws Exception { |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
43 |
try { |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
44 |
createGUI(); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
45 |
for (final LookAndFeelInfo laf : getInstalledLookAndFeels()) { |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
46 |
final String name = laf.getName(); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
47 |
if (name.contains("OS X") || name.contains("Metal")) { |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
48 |
SwingUtilities.invokeAndWait(() -> setLookAndFeel(laf)); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
49 |
SwingUtilities.invokeAndWait(() -> { |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
50 |
for (int i = 0; i < 4000; ++i) { |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
51 |
SwingUtilities.updateComponentTreeUI(frame); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
52 |
} |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
53 |
}); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
54 |
} |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
55 |
} |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
56 |
} finally { |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
57 |
EventQueue.invokeAndWait(() -> frame.dispose()); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
58 |
} |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
59 |
} |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
60 |
|
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
61 |
private static void createGUI() throws Exception { |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
62 |
EventQueue.invokeAndWait(() -> { |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
63 |
frame = new JFrame(); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
64 |
frame.setLayout(new FlowLayout()); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
65 |
|
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
66 |
frame.add(new JButton("JButton")); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
67 |
frame.add(new JCheckBox("JCheckBox")); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
68 |
frame.add(new JComboBox<>()); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
69 |
frame.add(new JEditorPane()); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
70 |
frame.add(new JFormattedTextField("JFormattedTextField")); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
71 |
frame.add(new JLabel("label")); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
72 |
frame.add(new JPanel()); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
73 |
frame.add(new JPasswordField("JPasswordField")); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
74 |
frame.add(new JProgressBar()); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
75 |
frame.add(new JRadioButton("JRadioButton")); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
76 |
frame.add(new JScrollBar()); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
77 |
frame.add(new JScrollPane()); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
78 |
frame.add(new JSeparator()); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
79 |
frame.add(new JSlider()); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
80 |
frame.add(new JSpinner()); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
81 |
frame.add(new JSplitPane()); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
82 |
frame.add(new JTabbedPane()); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
83 |
frame.add(new JTable()); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
84 |
frame.add(new JTextArea("JTextArea")); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
85 |
frame.add(new JTextField("JTextField")); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
86 |
frame.add(new JTextPane()); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
87 |
frame.add(new JToggleButton()); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
88 |
frame.add(new JToolBar()); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
89 |
frame.add(new JToolTip()); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
90 |
frame.add(new JTree()); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
91 |
frame.add(new JViewport()); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
92 |
|
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
93 |
final JMenuBar bar = new JMenuBar(); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
94 |
final JMenu menu1 = new JMenu("menu1"); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
95 |
final JMenu menu2 = new JMenu("menu2"); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
96 |
menu1.add(new JMenuItem("menuitem")); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
97 |
menu2.add(new JCheckBoxMenuItem("JCheckBoxMenuItem")); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
98 |
menu2.add(new JRadioButtonMenuItem("JRadioButtonMenuItem")); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
99 |
bar.add(menu1); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
100 |
bar.add(menu2); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
101 |
frame.setJMenuBar(bar); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
102 |
|
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
103 |
final String[] data = {"one", "two", "three", "four"}; |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
104 |
final JList<String> list = new JList<>(data); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
105 |
frame.add(list); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
106 |
|
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
107 |
final JDesktopPane pane = new JDesktopPane(); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
108 |
final JInternalFrame internalFrame = new JInternalFrame(); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
109 |
internalFrame.setBounds(10, 10, 130, 130); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
110 |
internalFrame.setVisible(true); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
111 |
pane.add(internalFrame); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
112 |
pane.setSize(150, 150); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
113 |
|
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
114 |
frame.add(pane); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
115 |
frame.pack(); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
116 |
frame.setSize(600, 600); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
117 |
frame.setLocationRelativeTo(null); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
118 |
// Commented to prevent a reference from RepaintManager |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
119 |
// frame.setVisible(true); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
120 |
}); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
121 |
} |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
122 |
|
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
123 |
private static void setLookAndFeel(final LookAndFeelInfo laf) { |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
124 |
try { |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
125 |
UIManager.setLookAndFeel(laf.getClassName()); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
126 |
System.out.println("LookAndFeel: " + laf.getClassName()); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
127 |
} catch (ClassNotFoundException | InstantiationException | |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
128 |
UnsupportedLookAndFeelException | IllegalAccessException e) { |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
129 |
throw new RuntimeException(e); |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
130 |
} |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
131 |
} |
8ff453aa551b
8134947: [macosx] Various memory leaks in Aqua look and feel
serb
parents:
diff
changeset
|
132 |
} |