Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/jdk/java/awt/Frame/SetMinimumSizeTest/SetMinimumSizeTest2.java
66645 views
1
/*
2
* Copyright (c) 2022, 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
* @key headful
27
* @summary Verify frame resizes back to minimumSize on calling pack
28
* @run main SetMinimumSizeTest2
29
*/
30
31
import java.awt.Button;
32
import java.awt.Dimension;
33
import java.awt.EventQueue;
34
import java.awt.Frame;
35
import java.awt.Robot;
36
37
public class SetMinimumSizeTest2 {
38
39
private static Frame frame;
40
private static volatile Dimension dimension;
41
private static volatile Dimension actualDimension;
42
43
public static void createGUI() {
44
frame = new Frame();
45
frame.add(new Button("Button"));
46
frame.setMinimumSize(new Dimension(140, 140));
47
frame.setLocationRelativeTo(null);
48
frame.setVisible(true);
49
}
50
51
public static void doTest() throws Exception {
52
try {
53
EventQueue.invokeAndWait(() -> createGUI());
54
55
Robot robot = new Robot();
56
robot.setAutoDelay(100);
57
robot.waitForIdle();
58
59
EventQueue.invokeAndWait(() -> {
60
dimension = frame.getSize();
61
});
62
63
EventQueue.invokeAndWait(() -> {
64
frame.setSize(dimension.width + 20, dimension.height + 20);
65
frame.invalidate();
66
frame.validate();
67
});
68
69
robot.waitForIdle();
70
71
EventQueue.invokeAndWait(() -> {
72
frame.pack();
73
frame.invalidate();
74
frame.validate();
75
});
76
77
robot.waitForIdle();
78
79
EventQueue.invokeAndWait(() -> {
80
actualDimension = frame.getSize();
81
});
82
83
if (!actualDimension.equals(dimension)) {
84
throw new RuntimeException("Test Failed\n"
85
+ "expected dimension:(" + dimension.width + "," + dimension.height +")\n"
86
+ "actual dimension:(" + actualDimension.width + "," + actualDimension.height + ")");
87
}
88
} finally {
89
EventQueue.invokeAndWait(() -> frame.dispose());
90
}
91
}
92
93
public static void main(String[] args) throws Exception {
94
doTest();
95
}
96
}
97
98
99