Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JScrollBar/4865918/bug4865918.java
41153 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
* @key headful
27
* @bug 4865918
28
* @summary REGRESSION:JCK1.4a-runtime api/javax_swing/interactive/JScrollBarTests.html#JScrollBar
29
* @author Andrey Pikalev
30
* @run main bug4865918
31
*/
32
33
import javax.swing.*;
34
import java.awt.*;
35
import java.awt.event.*;
36
import java.util.*;
37
38
public class bug4865918 {
39
40
private static TestScrollBar sbar;
41
private static JFrame frame;
42
43
public static void main(String[] argv) throws Exception {
44
try {
45
Robot robot = new Robot();
46
SwingUtilities.invokeAndWait(new Runnable() {
47
48
public void run() {
49
createAndShowGUI();
50
}
51
});
52
53
robot.waitForIdle();
54
55
SwingUtilities.invokeAndWait(new Runnable() {
56
57
@Override
58
public void run() {
59
sbar.pressMouse();
60
}
61
});
62
63
robot.waitForIdle();
64
65
int value = getValue();
66
67
if (value != 9) {
68
throw new Error("The scrollbar block increment is incorect");
69
}
70
} finally {
71
if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());
72
}
73
}
74
75
private static int getValue() throws Exception {
76
final int[] result = new int[1];
77
78
SwingUtilities.invokeAndWait(new Runnable() {
79
@Override
80
public void run() {
81
result[0] = sbar.getValue();
82
}
83
});
84
85
return result[0];
86
}
87
88
private static void createAndShowGUI() {
89
frame = new JFrame("bug4865918");
90
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
91
92
sbar = new TestScrollBar(JScrollBar.HORIZONTAL, -1, 10, -100, 100);
93
sbar.setPreferredSize(new Dimension(200, 20));
94
sbar.setBlockIncrement(10);
95
96
frame.getContentPane().add(sbar);
97
frame.pack();
98
frame.setVisible(true);
99
100
}
101
102
static class TestScrollBar extends JScrollBar {
103
104
public TestScrollBar(int orientation, int value, int extent,
105
int min, int max) {
106
super(orientation, value, extent, min, max);
107
108
}
109
110
public void pressMouse() {
111
MouseEvent me = new MouseEvent(sbar,
112
MouseEvent.MOUSE_PRESSED,
113
(new Date()).getTime(),
114
MouseEvent.BUTTON1_MASK,
115
3 * getWidth() / 4, getHeight() / 2,
116
1, true);
117
processMouseEvent(me);
118
}
119
}
120
}
121
122