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