1 /*
   2  * Copyright (c) 2020, 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 /*
  25  * @test
  26  * @bug 8240654
  27  * @summary Test painting a large window works
  28  * @key headful
  29  * @requires (os.family == "windows")
  30  * @requires vm.gc.Z
  31  * @run main/othervm -Dsun.java2d.uiScale=1 LargeWindowPaintTest
  32  * @run main/othervm -Dsun.java2d.uiScale=1 -Dsun.java2d.d3d=false LargeWindowPaintTest
  33  * @run main/othervm -XX:+UseZGC -Dsun.java2d.uiScale=1 LargeWindowPaintTest
  34  * @run main/othervm -XX:+UseZGC -Dsun.java2d.uiScale=1 -Dsun.java2d.d3d=false LargeWindowPaintTest
  35  */
  36 
  37 import java.awt.Color;
  38 import java.awt.Frame;
  39 import java.awt.Graphics;
  40 import java.awt.Rectangle;
  41 import java.awt.Robot;
  42 
  43 import javax.swing.JFrame;
  44 import javax.swing.JPanel;
  45 import javax.swing.SwingUtilities;
  46 import javax.swing.WindowConstants;
  47 
  48 public class LargeWindowPaintTest extends JPanel {
  49 
  50     static volatile JFrame frame = null;
  51     static volatile LargeWindowPaintTest comp = null;
  52     static Color color = Color.red;
  53 
  54     public static void main(String[] args) throws Exception {
  55 
  56         SwingUtilities.invokeAndWait(() -> {
  57             frame = new JFrame("Large Window Paint Test");
  58             frame.add(comp = new LargeWindowPaintTest());
  59             frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  60             frame.setExtendedState(Frame.MAXIMIZED_BOTH);
  61             frame.setVisible(true);
  62         });
  63 
  64         Thread.sleep(2000);
  65         Robot robot = new Robot();
  66         robot.setAutoDelay(500);
  67         robot.waitForIdle();
  68         Rectangle r = comp.getBounds();
  69         System.out.println("Component bounds = " + r);
  70         Color c = robot.getPixelColor((int)r.getWidth()-100, (int)r.getHeight()-100);
  71 
  72         SwingUtilities.invokeAndWait(() -> frame.dispose());
  73 
  74         if (!c.equals(color)) {
  75             throw new RuntimeException("Color was " + c + " expected " + color);
  76         }
  77     }
  78 
  79     @Override
  80     protected void paintComponent(Graphics g) {
  81         super.paintComponent(g);
  82         g.setColor(color);
  83         g.fillRect(0, 0, getSize().width, getSize().height);
  84     };
  85 }