Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/ScrollPane/ScrollPaneValidateTest.java
47490 views
1
/*
2
* Copyright (c) 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
/*
25
* @test
26
* @bug 8195738
27
* @summary scroll position in ScrollPane is reset after calling validate()
28
* @run main ScrollPaneValidateTest
29
*/
30
31
import java.awt.ScrollPane;
32
import java.awt.BorderLayout;
33
import java.awt.GridLayout;
34
import java.awt.Button;
35
import java.awt.Dimension;
36
import java.awt.Frame;
37
import java.awt.Panel;
38
import java.awt.Point;
39
import java.awt.Robot;
40
import java.awt.AWTException;
41
42
public class ScrollPaneValidateTest extends Frame {
43
ScrollPane pane;
44
45
public ScrollPaneValidateTest() {
46
setBounds(300, 300, 300, 300);
47
pane = new ScrollPane(ScrollPane.SCROLLBARS_NEVER);
48
add(pane, BorderLayout.NORTH);
49
pane.add(new InnerPanel());
50
}
51
52
public static void main(String[] args) throws AWTException {
53
Robot robot = new Robot();
54
final ScrollPaneValidateTest obj = new ScrollPaneValidateTest();
55
obj.setVisible(true);
56
57
// set to some scroll position
58
obj.pane.setScrollPosition(600, 200);
59
60
// get the newly set position
61
Point scrollPosition = obj.pane.getScrollPosition();
62
63
// call validate multiple times
64
obj.pane.validate();
65
robot.delay(1000);
66
obj.pane.validate();
67
robot.delay(1000);
68
69
// compare position after calling the validate function
70
if(!scrollPosition.equals(obj.pane.getScrollPosition())) {
71
obj.dispose();
72
throw new RuntimeException("Scrolling position is changed in ScrollPane");
73
}
74
75
obj.dispose();
76
return;
77
}
78
79
class InnerPanel extends Panel {
80
public InnerPanel() {
81
this.setLayout(new GridLayout(2, 4));
82
for (int i = 1; i <= 8; i++) {
83
this.add(new Button("Button" + i));
84
}
85
}
86
87
public Dimension getPreferredSize() {
88
return new Dimension(980, 200);
89
}
90
}
91
}
92
93