Path: blob/master/test/jdk/java/awt/Graphics2D/LargeWindowPaintTest.java
41152 views
/*1* Copyright (c) 2020, 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/*24* @test25* @bug 824065426* @summary Test painting a large window works27* @key headful28* @requires (os.family == "windows")29* @requires vm.gc.Z30* @run main/othervm -Dsun.java2d.uiScale=1 LargeWindowPaintTest31* @run main/othervm -Dsun.java2d.uiScale=1 -Dsun.java2d.d3d=false LargeWindowPaintTest32* @run main/othervm -XX:+UseZGC -Dsun.java2d.uiScale=1 LargeWindowPaintTest33* @run main/othervm -XX:+UseZGC -Dsun.java2d.uiScale=1 -Dsun.java2d.d3d=false LargeWindowPaintTest34*/3536import java.awt.Color;37import java.awt.Frame;38import java.awt.Graphics;39import java.awt.Rectangle;40import java.awt.Robot;4142import javax.swing.JFrame;43import javax.swing.JPanel;44import javax.swing.SwingUtilities;45import javax.swing.WindowConstants;4647public class LargeWindowPaintTest extends JPanel {4849static volatile JFrame frame = null;50static volatile LargeWindowPaintTest comp = null;51static Color color = Color.red;5253public static void main(String[] args) throws Exception {5455SwingUtilities.invokeAndWait(() -> {56frame = new JFrame("Large Window Paint Test");57frame.add(comp = new LargeWindowPaintTest());58frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);59frame.setExtendedState(Frame.MAXIMIZED_BOTH);60frame.setVisible(true);61});6263Thread.sleep(2000);64Robot robot = new Robot();65robot.setAutoDelay(500);66robot.waitForIdle();67Rectangle r = comp.getBounds();68System.out.println("Component bounds = " + r);69Color c = robot.getPixelColor((int)r.getWidth()-100, (int)r.getHeight()-100);7071SwingUtilities.invokeAndWait(() -> frame.dispose());7273if (!c.equals(color)) {74throw new RuntimeException("Color was " + c + " expected " + color);75}76}7778@Override79protected void paintComponent(Graphics g) {80super.paintComponent(g);81g.setColor(color);82g.fillRect(0, 0, getSize().width, getSize().height);83};84}858687