1 /*
   2  * Copyright (c) 2017, 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.Color;
  25 import java.awt.Rectangle;
  26 import java.awt.Robot;
  27 import javax.swing.JFrame;
  28 import javax.swing.JPanel;
  29 import javax.swing.SwingUtilities;
  30 
  31 /**
  32  * @test
  33  * @bug 8175301
  34  * @summary Java GUI hangs on Windows when Display set to 125% 
  35  * @run main/othervm -Dsun.java2d.uiScale=2 ScaledFrameBackgroundTest
  36  * @run main/othervm -Dsun.java2d.uiScale=2 -Dsun.java2d.d3d=true ScaledFrameBackgroundTest
  37  * @run main/othervm -Dsun.java2d.uiScale=2 -Dsun.java2d.opengl=true ScaledFrameBackgroundTest
  38  */
  39 public class ScaledFrameBackgroundTest {
  40 
  41     private static final Color BACKGROUND = Color.RED;
  42     private static JFrame frame;
  43 
  44     public static void main(String[] args) throws Exception {
  45 
  46         Robot robot = new Robot();
  47         robot.setAutoDelay(50);
  48 
  49         SwingUtilities.invokeAndWait(() -> {
  50             frame = new JFrame();
  51             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  52             frame.setSize(400, 300);
  53             JPanel panel = new JPanel();
  54             panel.setBackground(BACKGROUND);
  55             frame.getContentPane().add(panel);
  56             frame.setVisible(true);
  57         });
  58 
  59         robot.waitForIdle();
  60 
  61         Rectangle[] rects = new Rectangle[1];
  62         SwingUtilities.invokeAndWait(() -> {
  63             rects[0] = frame.getBounds();
  64         });
  65 
  66         Rectangle bounds = rects[0];
  67 
  68         int x = bounds.x + bounds.width / 4;
  69         int y = bounds.y + bounds.height / 4;
  70 
  71         Color color = robot.getPixelColor(x, y);
  72         System.out.println("background: " + BACKGROUND);
  73         System.out.println("color     : " + color);
  74 
  75         if (!BACKGROUND.equals(color)) {
  76             throw new RuntimeException("Wrong backgound color!");
  77         }
  78 
  79         x = bounds.x + 3 * bounds.width / 4;
  80         y = bounds.y + 3 * bounds.height / 4;
  81 
  82         color = robot.getPixelColor(x, y);
  83         System.out.println("background: " + BACKGROUND);
  84         System.out.println("color     : " + color);
  85 
  86         if (!BACKGROUND.equals(color)) {
  87             throw new RuntimeException("Wrong backgound color!");
  88         }
  89     }
  90 }