Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JScrollPane/6274267/bug6274267.java
38918 views
1
/*
2
* Copyright (c) 2011, 2014, 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. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
/* @test
27
@bug 6274267
28
@summary Checks that ScrollPaneLayout properly calculates preferred
29
layout size.
30
@author Mikhail Lapshin
31
@run main bug6274267
32
*/
33
34
import javax.swing.*;
35
import java.awt.*;
36
37
public class bug6274267 {
38
private JFrame frame;
39
private Component left;
40
41
public static void main(String[] args) throws Exception {
42
final bug6274267 test = new bug6274267();
43
Robot robot = new Robot();
44
try {
45
SwingUtilities.invokeAndWait(new Runnable() {
46
public void run() {
47
test.setupUI1();
48
}
49
});
50
robot.waitForIdle();
51
SwingUtilities.invokeAndWait(new Runnable() {
52
public void run() {
53
test.setupUI2();
54
}
55
});
56
test.test();
57
} finally {
58
if (test.frame != null) {
59
test.frame.dispose();
60
}
61
}
62
}
63
64
private void setupUI1() {
65
frame = new JFrame();
66
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
67
68
left = new JPanel();
69
left.setPreferredSize(new Dimension(100, 100));
70
71
JPanel rightPanel = new JPanel();
72
rightPanel.setPreferredSize(new Dimension(100, 50));
73
Component right = new JScrollPane(rightPanel);
74
75
JSplitPane split =
76
new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, right);
77
78
frame = new JFrame();
79
frame.add(split);
80
frame.pack();
81
}
82
83
// It is important to separate frame.pack() from frame.setVisible(true).
84
// Otherwise the repaint manager will combine validate() calls and
85
// the bug won't appear.
86
private void setupUI2() {
87
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
88
frame.setLocationRelativeTo(null);
89
frame.setVisible(true);
90
}
91
92
private void test() throws Exception {
93
if (left.getSize().width == 100) {
94
System.out.println("Test passed");
95
} else {
96
throw new RuntimeException("ScrollPaneLayout sometimes improperly " +
97
"calculates the preferred layout size. ");
98
}
99
}
100
}
101
102