Path: blob/master/test/jdk/javax/swing/JRadioButton/8041561/bug8041561.java
41154 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* @key headful39* @bug 804156140* @author Alexander Scherbatiy41* @summary Inconsistent opacity behaviour between JCheckBox and JRadioButton42* @run main bug804156143*/44public class bug8041561 {4546private static JRadioButton radioButton;47private static JFrame frame;4849public static void main(String[] args) throws Exception {50try {51SwingUtilities.invokeAndWait(new Runnable() {5253@Override54public void run() {55try {56MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());57UIManager.setLookAndFeel(new MetalLookAndFeel());58createAndShowGUI();59} catch (UnsupportedLookAndFeelException e) {60throw new RuntimeException(e);61}62}63});6465new Robot().waitForIdle();66Thread.sleep(500);6768SwingUtilities.invokeAndWait(new Runnable() {6970@Override71public void run() {72try {73Point point = radioButton.getLocationOnScreen();74int x = (int) point.getX() + radioButton.getWidth() / 2;75int y = (int) point.getY() + radioButton.getHeight() / 2;7677Robot robot = new Robot();78Color color = robot.getPixelColor(x, y);79if (!Color.BLUE.equals(color)) {80throw new RuntimeException("JRadioButton is opaque");81}82} catch (AWTException e) {83throw new RuntimeException(e);84}85}86});87} finally {88if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());89}90}9192private static void createAndShowGUI() {93frame = new JFrame();94frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);95frame.setBackground(Color.BLUE);96radioButton = new JRadioButton();97radioButton.setOpaque(false);98JPanel panel = new JPanel();99panel.setBackground(Color.BLUE);100panel.add(radioButton);101frame.getContentPane().add(panel);102frame.pack();103frame.setVisible(true);104}105}106107108