Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JRadioButton/8041561/bug8041561.java
38854 views
/*1* Copyright (c) 2014, 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*/2223import java.awt.AWTException;24import java.awt.Color;25import java.awt.Point;26import java.awt.Robot;27import javax.swing.JFrame;28import javax.swing.JPanel;29import javax.swing.JRadioButton;30import javax.swing.SwingUtilities;31import javax.swing.UIManager;32import javax.swing.UnsupportedLookAndFeelException;33import javax.swing.plaf.metal.DefaultMetalTheme;34import javax.swing.plaf.metal.MetalLookAndFeel;3536/**37* @test38* @bug 804156139* @author Alexander Scherbatiy40* @summary Inconsistent opacity behaviour between JCheckBox and JRadioButton41* @run main bug804156142*/43public class bug8041561 {4445private static JRadioButton radioButton;4647public static void main(String[] args) throws Exception {48SwingUtilities.invokeAndWait(new Runnable() {4950@Override51public void run() {52try {53MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());54UIManager.setLookAndFeel(new MetalLookAndFeel());55createAndShowGUI();56} catch (UnsupportedLookAndFeelException e) {57throw new RuntimeException(e);58}59}60});6162new Robot().waitForIdle();63Thread.sleep(500);6465SwingUtilities.invokeAndWait(new Runnable() {6667@Override68public void run() {69try {70Point point = radioButton.getLocationOnScreen();71int x = (int) point.getX() + radioButton.getWidth() / 2;72int y = (int) point.getY() + radioButton.getHeight() / 2;7374Robot robot = new Robot();75Color color = robot.getPixelColor(x, y);76if (!Color.BLUE.equals(color)) {77throw new RuntimeException("JRadioButton is opaque");78}79} catch (AWTException e) {80throw new RuntimeException(e);81}82}83});8485}8687private static void createAndShowGUI() {88JFrame frame = new JFrame();89frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);90frame.setBackground(Color.BLUE);91radioButton = new JRadioButton();92radioButton.setOpaque(false);93JPanel panel = new JPanel();94panel.setBackground(Color.BLUE);95panel.add(radioButton);96frame.getContentPane().add(panel);97frame.pack();98frame.setVisible(true);99}100}101102103