3131
3232import java .awt .Dimension ;
3333import java .awt .Robot ;
34+ import java .awt .event .MouseAdapter ;
35+ import java .awt .event .MouseEvent ;
3436import javax .swing .JFrame ;
3537import javax .swing .JScrollBar ;
3638import javax .swing .SwingUtilities ;
37- import java .awt .event .MouseEvent ;
39+ import java .util .concurrent .CountDownLatch ;
40+ import java .util .concurrent .TimeUnit ;
3841
3942import java .util .Date ;
4043
4144public class bug4865918 {
4245
4346 private static TestScrollBar sbar ;
4447 private static JFrame frame ;
48+ private static final CountDownLatch mousePressLatch = new CountDownLatch (1 );
4549
4650 public static void main (String [] argv ) throws Exception {
4751 try {
@@ -52,6 +56,9 @@ public static void main(String[] argv) throws Exception {
5256 robot .delay (1000 );
5357
5458 SwingUtilities .invokeAndWait (() -> sbar .pressMouse ());
59+ if (!mousePressLatch .await (2 , TimeUnit .SECONDS )) {
60+ throw new RuntimeException ("Timed out waiting for mouse press" );
61+ }
5562
5663 robot .waitForIdle ();
5764 robot .delay (200 );
@@ -81,6 +88,11 @@ private static void createAndShowGUI() {
8188 sbar = new TestScrollBar (JScrollBar .HORIZONTAL , -1 , 10 , -100 , 100 );
8289 sbar .setPreferredSize (new Dimension (200 , 20 ));
8390 sbar .setBlockIncrement (10 );
91+ sbar .addMouseListener (new MouseAdapter () {
92+ public void mousePressed (MouseEvent e ) {
93+ mousePressLatch .countDown ();
94+ }
95+ });
8496
8597 frame .getContentPane ().add (sbar );
8698 frame .pack ();
0 commit comments