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  * @key headful
  34  * @bug 8175301
  35  * @summary Java GUI hangs on Windows when Display set to 125%
  36  * @run main/othervm -Dsun.java2d.uiScale=2 ScaledFrameBackgroundTest
  37  * @run main/othervm -Dsun.java2d.uiScale=2 -Dsun.java2d.d3d=true ScaledFrameBackgroundTest
  38  * @run main/othervm -Dsun.java2d.uiScale=2 -Dsun.java2d.opengl=true ScaledFrameBackgroundTest
  39  */
  40 public class ScaledFrameBackgroundTest {
  41 
  42     private static final Color BACKGROUND = Color.RED;
  43     private static JFrame frame;
  44 
  45     public static void main(String[] args) throws Exception {
  46 
  47         Robot robot = new Robot();
  48         robot.setAutoDelay(50);
  49 
  50         SwingUtilities.invokeAndWait(() -> {
  51             frame = new JFrame();
  52             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  53             frame.setSize(400, 300);
  54             JPanel panel = new JPanel();
  55             panel.setBackground(BACKGROUND);
  56             frame.getContentPane().add(panel);
  57             frame.setVisible(true);
  58         });
  59 
  60         robot.waitForIdle();
  61         Thread.sleep(200);
  62 
  63         Rectangle[] rects = new Rectangle[1];
  64         SwingUtilities.invokeAndWait(() -> {
  65             rects[0] = frame.getBounds();
  66         });
  67 
  68         Rectangle bounds = rects[0];
  69 
  70         int x = bounds.x + bounds.width / 4;
  71         int y = bounds.y + bounds.height / 4;
  72 
  73         Color color = robot.getPixelColor(x, y);
  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 
  84         if (!BACKGROUND.equals(color)) {
  85             throw new RuntimeException("Wrong backgound color!");
  86         }
  87     }
  88 }