Path: blob/master/test/jdk/javax/swing/JFrame/8175301/ScaledFrameBackgroundTest.java
41153 views
/*1* Copyright (c) 2017, 2018, 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*/2223import java.awt.Color;24import java.awt.Rectangle;25import java.awt.Robot;26import javax.swing.JFrame;27import javax.swing.JPanel;28import javax.swing.SwingUtilities;2930/**31* @test32* @key headful33* @bug 8175301 819861334* @summary Java GUI hangs on Windows when Display set to 125%35* @run main/othervm -Dsun.java2d.uiScale=2 ScaledFrameBackgroundTest36* @run main/othervm -Dsun.java2d.uiScale=2 -Dsun.java2d.d3d=true ScaledFrameBackgroundTest37*/38public class ScaledFrameBackgroundTest {3940private static final Color BACKGROUND = Color.RED;41private static JFrame frame;4243public static void main(String[] args) throws Exception {44try {45Robot robot = new Robot();46robot.setAutoDelay(100);4748SwingUtilities.invokeAndWait(() -> {49frame = new JFrame();50frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);51frame.setSize(400, 300);52JPanel panel = new JPanel();53panel.setBackground(BACKGROUND);54frame.getContentPane().add(panel);55frame.setVisible(true);56frame.setLocationRelativeTo(null);57});5859robot.waitForIdle();60robot.delay(1000);6162Rectangle[] rects = new Rectangle[1];63SwingUtilities.invokeAndWait(() -> {64rects[0] = frame.getBounds();65});6667Rectangle bounds = rects[0];6869int x = bounds.x + bounds.width / 4;70int y = bounds.y + bounds.height / 4;7172Color color = robot.getPixelColor(x, y);7374if (!BACKGROUND.equals(color)) {75throw new RuntimeException("Wrong backgound color!");76}7778x = bounds.x + 3 * bounds.width / 4;79y = bounds.y + 3 * bounds.height / 4;8081color = robot.getPixelColor(x, y);8283if (!BACKGROUND.equals(color)) {84throw new RuntimeException("Wrong backgound color!!");85}86} finally {87if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());88}89}90}919293