1 /* 2 * Copyright (c) 2014, 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 import java.awt.AWTException; 25 import java.awt.Color; 26 import java.awt.Point; 27 import java.awt.Robot; 28 import javax.swing.JFrame; 29 import javax.swing.JPanel; 30 import javax.swing.JRadioButton; 31 import javax.swing.SwingUtilities; 32 import javax.swing.UIManager; 33 import javax.swing.UnsupportedLookAndFeelException; 34 import javax.swing.plaf.metal.DefaultMetalTheme; 35 import javax.swing.plaf.metal.MetalLookAndFeel; 36 37 /** 38 * @test 39 * @key headful 40 * @bug 8041561 41 * @author Alexander Scherbatiy 42 * @summary Inconsistent opacity behaviour between JCheckBox and JRadioButton 43 * @run main bug8041561 44 */ 45 public class bug8041561 { 46 47 private static JRadioButton radioButton; 48 49 public static void main(String[] args) throws Exception { 50 SwingUtilities.invokeAndWait(new Runnable() { 51 52 @Override 53 public void run() { 54 try { 55 MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme()); 56 UIManager.setLookAndFeel(new MetalLookAndFeel()); 57 createAndShowGUI(); 58 } catch (UnsupportedLookAndFeelException e) { 59 throw new RuntimeException(e); 60 } 61 } 62 }); 63 64 new Robot().waitForIdle(); 65 Thread.sleep(500); 66 67 SwingUtilities.invokeAndWait(new Runnable() { 68 69 @Override 70 public void run() { 71 try { 72 Point point = radioButton.getLocationOnScreen(); 73 int x = (int) point.getX() + radioButton.getWidth() / 2; 74 int y = (int) point.getY() + radioButton.getHeight() / 2; 75 76 Robot robot = new Robot(); 77 Color color = robot.getPixelColor(x, y); 78 if (!Color.BLUE.equals(color)) { 79 throw new RuntimeException("JRadioButton is opaque"); 80 } 81 } catch (AWTException e) { 82 throw new RuntimeException(e); 83 } 84 } 85 }); 86 87 } 88 89 private static void createAndShowGUI() { 90 JFrame frame = new JFrame(); 91 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 92 frame.setBackground(Color.BLUE); 93 radioButton = new JRadioButton(); 94 radioButton.setOpaque(false); 95 JPanel panel = new JPanel(); 96 panel.setBackground(Color.BLUE); 97 panel.add(radioButton); 98 frame.getContentPane().add(panel); 99 frame.pack(); 100 frame.setVisible(true); 101 } 102 }