Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JFrame/8175301/ScaledFrameBackgroundTest.java
41153 views
1
/*
2
* Copyright (c) 2017, 2018, 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 8198613
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
*/
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
try {
46
Robot robot = new Robot();
47
robot.setAutoDelay(100);
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
frame.setLocationRelativeTo(null);
58
});
59
60
robot.waitForIdle();
61
robot.delay(1000);
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
} finally {
88
if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());
89
}
90
}
91
}
92
93