24
24
/*
25
25
* @test
26
26
* @bug 4865918
27
- * @requires (os.family != "mac")
27
+ * @key headful
28
28
* @summary REGRESSION:JCK1.4a-runtime api/javax_swing/interactive/JScrollBarTests.html#JScrollBar
29
29
* @run main bug4865918
30
30
*/
31
31
32
32
import java .awt .Dimension ;
33
+ import java .awt .Robot ;
33
34
import java .awt .event .MouseAdapter ;
34
35
import java .awt .event .MouseEvent ;
36
+ import javax .swing .JFrame ;
35
37
import javax .swing .JScrollBar ;
36
38
import javax .swing .SwingUtilities ;
37
39
import java .util .concurrent .CountDownLatch ;
41
43
42
44
public class bug4865918 {
43
45
46
+ private static JFrame frame ;
44
47
private static TestScrollBar sbar ;
45
48
private static final CountDownLatch mousePressLatch = new CountDownLatch (1 );
46
49
47
50
public static void main (String [] argv ) throws Exception {
48
- String osName = System .getProperty ("os.name" );
49
- if (osName .toLowerCase ().contains ("os x" )) {
50
- System .out .println ("This test is not for MacOS, considered passed." );
51
- return ;
52
- }
53
- SwingUtilities .invokeAndWait (() -> setupTest ());
51
+ try {
52
+ Robot robot = new Robot ();
53
+ SwingUtilities .invokeAndWait (() -> createAndShowGUI ());
54
54
55
- SwingUtilities .invokeAndWait (() -> sbar .pressMouse ());
56
- if (!mousePressLatch .await (2 , TimeUnit .SECONDS )) {
57
- throw new RuntimeException ("Timed out waiting for mouse press" );
58
- }
55
+ robot .waitForIdle ();
56
+ robot .delay (1000 );
57
+
58
+ SwingUtilities .invokeAndWait (() -> sbar .pressMouse ());
59
+ if (!mousePressLatch .await (2 , TimeUnit .SECONDS )) {
60
+ throw new RuntimeException ("Timed out waiting for mouse press" );
61
+ }
59
62
60
- if (getValue () != 9 ) {
61
- throw new RuntimeException ("The scrollbar block increment is incorrect" );
63
+ if (getValue () != 9 ) {
64
+ throw new RuntimeException ("The scrollbar block increment " +
65
+ getValue () + " is incorrect" );
66
+ }
67
+ } finally {
68
+ SwingUtilities .invokeAndWait (() -> {
69
+ if (frame != null ) {
70
+ frame .dispose ();
71
+ }
72
+ });
62
73
}
63
74
}
64
75
@@ -73,8 +84,8 @@ private static int getValue() throws Exception {
73
84
return result [0 ];
74
85
}
75
86
76
- private static void setupTest () {
77
-
87
+ private static void createAndShowGUI () {
88
+ frame = new JFrame ( "bug4865918" );
78
89
sbar = new TestScrollBar (JScrollBar .HORIZONTAL , -1 , 10 , -100 , 100 );
79
90
sbar .setPreferredSize (new Dimension (200 , 20 ));
80
91
sbar .setBlockIncrement (10 );
@@ -83,7 +94,11 @@ public void mousePressed(MouseEvent e) {
83
94
mousePressLatch .countDown ();
84
95
}
85
96
});
86
-
97
+ frame .getContentPane ().add (sbar );
98
+ frame .pack ();
99
+ frame .setLocationRelativeTo (null );
100
+ frame .setVisible (true );
101
+ frame .toFront ();
87
102
}
88
103
89
104
static class TestScrollBar extends JScrollBar {
0 commit comments