1 /*
2  * Copyright (c) 2012, 2018, 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  * @library /test/lib
29  * @modules java.desktop/sun.awt
30  * @build jdk.test.lib.Platform
31  * @run applet/manual=yesno bug4449413.html
32  */
33 
34 import javax.swing.*;
35 import javax.swing.plaf.metal.*;
36 import java.awt.event.*;
37 import java.awt.*;
38 
39 import jdk.test.lib.Platform;
40 
41 public class bug4449413 extends JApplet {
42 
43     @Override
init()44     public void init() {
45 
46         try {
47 
48             if (Platform.isOSX()) {
49                 UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
50             }
51 
52             final MetalTheme oceanTheme = (MetalTheme) sun.awt.AppContext.getAppContext().get("currentMetalTheme");
53 
54 
55             SwingUtilities.invokeAndWait(new Runnable() {
56 
57                 @Override
58                 public void run() {
59                     getContentPane().setLayout(new FlowLayout());
60                     final JPanel panel = new JPanel();
61 
62                     JCheckBox box = new JCheckBox("Use Ocean theme", true);
63                     getContentPane().add(box);
64                     box.addItemListener(new ItemListener() {
65 
66                         @Override
67                         public void itemStateChanged(ItemEvent e) {
68                             if (e.getStateChange() == ItemEvent.SELECTED) {
69                                 MetalLookAndFeel.setCurrentTheme(oceanTheme);
70                             } else {
71                                 MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
72                             }
73                             SwingUtilities.updateComponentTreeUI(panel);
74                         }
75                     });
76 
77                     getContentPane().add(panel);
78                     panel.setLayout(new GridLayout(4, 6, 10, 15));
79                     for (int k = 0; k <= 3; k++) {
80                         for (int j = 1; j >= 0; j--) {
81                             AbstractButton b = createButton(j, k);
82                             panel.add(b);
83                         }
84                     }
85                 }
86             });
87 
88         } catch (Exception e) {
89             throw new RuntimeException(e);
90         }
91     }
92 
createButton(int enabled, int type)93     static AbstractButton createButton(int enabled, int type) {
94         AbstractButton b = null;
95         switch (type) {
96             case 0:
97                 b = new JRadioButton("RadioButton");
98                 break;
99             case 1:
100                 b = new JCheckBox("CheckBox");
101                 break;
102             case 2:
103                 b = new JRadioButtonMenuItem("RBMenuItem");
104                 break;
105             case 3:
106                 b = new JCheckBoxMenuItem("CBMenuItem");
107                 break;
108         }
109         b.setBackground(Color.black);
110         b.setForeground(Color.white);
111         b.setEnabled(enabled == 1);
112         b.setSelected(true);
113         return b;
114     }
115 }
116