Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JComponent/6683775/bug6683775.java
38918 views
/*1* Copyright (c) 2009, 2013, 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 6683775 679476425@summary Painting artifacts is seen when panel is made setOpaque(false) for a translucent window26@author Alexander Potochkin27@run main bug668377528*/2930import com.sun.awt.AWTUtilities;31import sun.awt.SunToolkit;3233import javax.swing.*;34import java.awt.*;35import java.awt.image.BufferedImage;3637public class bug6683775 {38public static void main(String[] args) throws Exception {39GraphicsConfiguration gc = getGC();40if (!AWTUtilities.isTranslucencySupported(41AWTUtilities.Translucency.PERPIXEL_TRANSLUCENT)42|| gc == null) {43return;44}45SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();46Robot robot = new Robot();47final JFrame testFrame = new JFrame(gc);4849SwingUtilities.invokeLater(new Runnable() {50public void run() {51JFrame backgroundFrame = new JFrame("Background frame");52backgroundFrame.setUndecorated(true);53JPanel panel = new JPanel();54panel.setBackground(Color.RED);55backgroundFrame.add(panel);56backgroundFrame.setSize(200, 200);57backgroundFrame.setVisible(true);5859testFrame.setUndecorated(true);60JPanel p = new JPanel();61p.setOpaque(false);62testFrame.add(p);63AWTUtilities.setWindowOpaque(testFrame, false);64testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);65testFrame.setSize(400, 400);66testFrame.setLocation(0, 0);67testFrame.setVisible(true);68}69});7071toolkit.realSync();7273//robot.getPixelColor() didn't work right for some reason74BufferedImage capture = robot.createScreenCapture(new Rectangle(100, 100));7576int redRGB = Color.RED.getRGB();77if (redRGB != capture.getRGB(10, 10)) {78throw new RuntimeException("Transparent frame is not transparent!");79}80}8182private static GraphicsConfiguration getGC() {83GraphicsConfiguration transparencyCapableGC =84GraphicsEnvironment.getLocalGraphicsEnvironment()85.getDefaultScreenDevice().getDefaultConfiguration();86if (!AWTUtilities.isTranslucencyCapable(transparencyCapableGC)) {87transparencyCapableGC = null;8889GraphicsEnvironment env =90GraphicsEnvironment.getLocalGraphicsEnvironment();91GraphicsDevice[] devices = env.getScreenDevices();9293for (int i = 0; i < devices.length && transparencyCapableGC == null; i++) {94GraphicsConfiguration[] configs = devices[i].getConfigurations();95for (int j = 0; j < configs.length && transparencyCapableGC == null; j++) {96if (AWTUtilities.isTranslucencyCapable(configs[j])) {97transparencyCapableGC = configs[j];98}99}100}101}102return transparencyCapableGC;103}104}105106107