Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JScrollPane/6274267/bug6274267.java
41153 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
/*
27
* @test
28
* @key headful
29
* @bug 6274267
30
* @summary Checks that ScrollPaneLayout properly calculates preferred
31
* layout size.
32
* @author Mikhail Lapshin
33
* @run main bug6274267
34
*/
35
36
import javax.swing.*;
37
import java.awt.*;
38
39
public class bug6274267 {
40
private JFrame frame;
41
private Component left;
42
43
public static void main(String[] args) throws Exception {
44
final bug6274267 test = new bug6274267();
45
Robot robot = new Robot();
46
try {
47
SwingUtilities.invokeAndWait(new Runnable() {
48
public void run() {
49
test.setupUI1();
50
}
51
});
52
robot.waitForIdle();
53
SwingUtilities.invokeAndWait(new Runnable() {
54
public void run() {
55
test.setupUI2();
56
}
57
});
58
test.test();
59
} finally {
60
if (test.frame != null) {
61
test.frame.dispose();
62
}
63
}
64
}
65
66
private void setupUI1() {
67
frame = new JFrame();
68
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
69
70
left = new JPanel();
71
left.setPreferredSize(new Dimension(100, 100));
72
73
JPanel rightPanel = new JPanel();
74
rightPanel.setPreferredSize(new Dimension(100, 50));
75
Component right = new JScrollPane(rightPanel);
76
77
JSplitPane split =
78
new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, right);
79
80
frame = new JFrame();
81
frame.add(split);
82
frame.pack();
83
}
84
85
// It is important to separate frame.pack() from frame.setVisible(true).
86
// Otherwise the repaint manager will combine validate() calls and
87
// the bug won't appear.
88
private void setupUI2() {
89
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
90
frame.setLocationRelativeTo(null);
91
frame.setVisible(true);
92
}
93
94
private void test() throws Exception {
95
if (left.getSize().width == 100) {
96
System.out.println("Test passed");
97
} else {
98
throw new RuntimeException("ScrollPaneLayout sometimes improperly " +
99
"calculates the preferred layout size. ");
100
}
101
}
102
}
103
104