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/JScrollBar/4708809/bug4708809.java
38918 views
1
/*
2
* Copyright (c) 2011, 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 4708809
27
* @summary JScrollBar functionality slightly different from native scrollbar
28
* @author Andrey Pikalev
29
* @run main bug4708809
30
*/
31
import javax.swing.*;
32
import java.awt.*;
33
import java.awt.Point;
34
import java.awt.event.*;
35
36
public class bug4708809 {
37
38
private static volatile boolean do_test = false;
39
private static volatile boolean passed = true;
40
private static JScrollPane spane;
41
private static JScrollBar sbar;
42
43
public static void main(String[] args) throws Exception {
44
Robot robot = new Robot();
45
robot.setAutoDelay(350);
46
47
SwingUtilities.invokeAndWait(new Runnable() {
48
49
public void run() {
50
createAndShowGUI();
51
}
52
});
53
54
robot.waitForIdle();
55
56
SwingUtilities.invokeAndWait(new Runnable() {
57
58
public void run() {
59
spane.requestFocus();
60
sbar.setValue(sbar.getMaximum());
61
}
62
});
63
64
robot.waitForIdle();
65
66
Point point = getClickPoint(0.5, 0.5);
67
robot.mouseMove(point.x, point.y);
68
robot.mousePress(InputEvent.BUTTON1_MASK);
69
70
robot.waitForIdle();
71
72
SwingUtilities.invokeAndWait(new Runnable() {
73
74
public void run() {
75
final int oldValue = sbar.getValue();
76
sbar.addAdjustmentListener(new AdjustmentListener() {
77
78
public void adjustmentValueChanged(AdjustmentEvent e) {
79
if (e.getValue() >= oldValue) {
80
passed = false;
81
}
82
do_test = true;
83
}
84
});
85
86
}
87
});
88
89
robot.waitForIdle();
90
91
point = getClickPoint(0.5, 0.2);
92
robot.mouseMove(point.x, point.y);
93
robot.mouseRelease(InputEvent.BUTTON1_MASK);
94
robot.waitForIdle();
95
96
if (!do_test || !passed) {
97
throw new Exception("The scrollbar moved with incorrect direction");
98
}
99
100
}
101
102
private static Point getClickPoint(final double scaleX, final double scaleY) throws Exception {
103
final Point[] result = new Point[1];
104
105
SwingUtilities.invokeAndWait(new Runnable() {
106
107
@Override
108
public void run() {
109
Point p = sbar.getLocationOnScreen();
110
Rectangle rect = sbar.getBounds();
111
result[0] = new Point((int) (p.x + scaleX * rect.width),
112
(int) (p.y + scaleY * rect.height));
113
}
114
});
115
116
return result[0];
117
118
}
119
120
private static void createAndShowGUI() {
121
JFrame fr = new JFrame("Test");
122
123
JLabel label = new JLabel("picture");
124
label.setPreferredSize(new Dimension(500, 500));
125
spane = new JScrollPane(label);
126
fr.getContentPane().add(spane);
127
sbar = spane.getVerticalScrollBar();
128
129
fr.setSize(200, 200);
130
fr.setVisible(true);
131
}
132
}
133
134