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