Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JCheckBox/4449413/bug4449413.java
32273 views
1
/*
2
* Copyright (c) 2012, 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
/* @test
25
* @bug 4449413
26
* @summary Tests that checkbox and radiobuttons' check marks are visible when background is black
27
* @author Ilya Boyandin
28
* @run applet/manual=yesno bug4449413.html
29
*/
30
31
import javax.swing.*;
32
import javax.swing.plaf.metal.*;
33
import java.awt.event.*;
34
import java.awt.*;
35
import sun.awt.OSInfo;
36
37
public class bug4449413 extends JApplet {
38
39
@Override
40
public void init() {
41
42
try {
43
44
if (OSInfo.getOSType() == OSInfo.OSType.MACOSX) {
45
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
46
}
47
48
final MetalTheme oceanTheme = (MetalTheme) sun.awt.AppContext.getAppContext().get("currentMetalTheme");
49
50
51
SwingUtilities.invokeAndWait(new Runnable() {
52
53
@Override
54
public void run() {
55
getContentPane().setLayout(new FlowLayout());
56
final JPanel panel = new JPanel();
57
58
JCheckBox box = new JCheckBox("Use Ocean theme", true);
59
getContentPane().add(box);
60
box.addItemListener(new ItemListener() {
61
62
@Override
63
public void itemStateChanged(ItemEvent e) {
64
if (e.getStateChange() == ItemEvent.SELECTED) {
65
MetalLookAndFeel.setCurrentTheme(oceanTheme);
66
} else {
67
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
68
}
69
SwingUtilities.updateComponentTreeUI(panel);
70
}
71
});
72
73
getContentPane().add(panel);
74
panel.setLayout(new GridLayout(4, 6, 10, 15));
75
for (int k = 0; k <= 3; k++) {
76
for (int j = 1; j >= 0; j--) {
77
AbstractButton b = createButton(j, k);
78
panel.add(b);
79
}
80
}
81
}
82
});
83
84
} catch (Exception e) {
85
throw new RuntimeException(e);
86
}
87
}
88
89
static AbstractButton createButton(int enabled, int type) {
90
AbstractButton b = null;
91
switch (type) {
92
case 0:
93
b = new JRadioButton("RadioButton");
94
break;
95
case 1:
96
b = new JCheckBox("CheckBox");
97
break;
98
case 2:
99
b = new JRadioButtonMenuItem("RBMenuItem");
100
break;
101
case 3:
102
b = new JCheckBoxMenuItem("CBMenuItem");
103
break;
104
}
105
b.setBackground(Color.black);
106
b.setForeground(Color.white);
107
b.setEnabled(enabled == 1);
108
b.setSelected(true);
109
return b;
110
}
111
}
112
113