Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JCheckBox/4449413/bug4449413.java
32273 views
/*1* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @bug 444941325* @summary Tests that checkbox and radiobuttons' check marks are visible when background is black26* @author Ilya Boyandin27* @run applet/manual=yesno bug4449413.html28*/2930import javax.swing.*;31import javax.swing.plaf.metal.*;32import java.awt.event.*;33import java.awt.*;34import sun.awt.OSInfo;3536public class bug4449413 extends JApplet {3738@Override39public void init() {4041try {4243if (OSInfo.getOSType() == OSInfo.OSType.MACOSX) {44UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");45}4647final MetalTheme oceanTheme = (MetalTheme) sun.awt.AppContext.getAppContext().get("currentMetalTheme");484950SwingUtilities.invokeAndWait(new Runnable() {5152@Override53public void run() {54getContentPane().setLayout(new FlowLayout());55final JPanel panel = new JPanel();5657JCheckBox box = new JCheckBox("Use Ocean theme", true);58getContentPane().add(box);59box.addItemListener(new ItemListener() {6061@Override62public void itemStateChanged(ItemEvent e) {63if (e.getStateChange() == ItemEvent.SELECTED) {64MetalLookAndFeel.setCurrentTheme(oceanTheme);65} else {66MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());67}68SwingUtilities.updateComponentTreeUI(panel);69}70});7172getContentPane().add(panel);73panel.setLayout(new GridLayout(4, 6, 10, 15));74for (int k = 0; k <= 3; k++) {75for (int j = 1; j >= 0; j--) {76AbstractButton b = createButton(j, k);77panel.add(b);78}79}80}81});8283} catch (Exception e) {84throw new RuntimeException(e);85}86}8788static AbstractButton createButton(int enabled, int type) {89AbstractButton b = null;90switch (type) {91case 0:92b = new JRadioButton("RadioButton");93break;94case 1:95b = new JCheckBox("CheckBox");96break;97case 2:98b = new JRadioButtonMenuItem("RBMenuItem");99break;100case 3:101b = new JCheckBoxMenuItem("CBMenuItem");102break;103}104b.setBackground(Color.black);105b.setForeground(Color.white);106b.setEnabled(enabled == 1);107b.setSelected(true);108return b;109}110}111112113