31
31
32
32
import java .awt .Dimension ;
33
33
import java .awt .Robot ;
34
+ import java .awt .event .MouseAdapter ;
35
+ import java .awt .event .MouseEvent ;
34
36
import javax .swing .JFrame ;
35
37
import javax .swing .JScrollBar ;
36
38
import javax .swing .SwingUtilities ;
37
- import java .awt .event .MouseEvent ;
39
+ import java .util .concurrent .CountDownLatch ;
40
+ import java .util .concurrent .TimeUnit ;
38
41
39
42
import java .util .Date ;
40
43
41
44
public class bug4865918 {
42
45
43
46
private static TestScrollBar sbar ;
44
47
private static JFrame frame ;
48
+ private static final CountDownLatch mousePressLatch = new CountDownLatch (1 );
45
49
46
50
public static void main (String [] argv ) throws Exception {
47
51
try {
@@ -52,6 +56,9 @@ public static void main(String[] argv) throws Exception {
52
56
robot .delay (1000 );
53
57
54
58
SwingUtilities .invokeAndWait (() -> sbar .pressMouse ());
59
+ if (!mousePressLatch .await (2 , TimeUnit .SECONDS )) {
60
+ throw new RuntimeException ("Timed out waiting for mouse press" );
61
+ }
55
62
56
63
robot .waitForIdle ();
57
64
robot .delay (200 );
@@ -81,6 +88,11 @@ private static void createAndShowGUI() {
81
88
sbar = new TestScrollBar (JScrollBar .HORIZONTAL , -1 , 10 , -100 , 100 );
82
89
sbar .setPreferredSize (new Dimension (200 , 20 ));
83
90
sbar .setBlockIncrement (10 );
91
+ sbar .addMouseListener (new MouseAdapter () {
92
+ public void mousePressed (MouseEvent e ) {
93
+ mousePressLatch .countDown ();
94
+ }
95
+ });
84
96
85
97
frame .getContentPane ().add (sbar );
86
98
frame .pack ();
0 commit comments