11/*
2- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2626 * @key headful
2727 * @bug 4865918
2828 * @summary REGRESSION:JCK1.4a-runtime api/javax_swing/interactive/JScrollBarTests.html#JScrollBar
29- * @author Andrey Pikalev
3029 * @run main bug4865918
3130 */
3231
33- import javax .swing .*;
34- import java .awt .*;
35- import java .awt .event .*;
36- import java .util .*;
32+ import java .awt .Dimension ;
33+ import java .awt .Robot ;
34+ import javax .swing .JFrame ;
35+ import javax .swing .JScrollBar ;
36+ import javax .swing .SwingUtilities ;
37+ import java .awt .event .MouseEvent ;
38+
39+ import java .util .Date ;
3740
3841public class bug4865918 {
3942
@@ -43,29 +46,18 @@ public class bug4865918 {
4346 public static void main (String [] argv ) throws Exception {
4447 try {
4548 Robot robot = new Robot ();
46- SwingUtilities .invokeAndWait (new Runnable () {
47-
48- public void run () {
49- createAndShowGUI ();
50- }
51- });
49+ SwingUtilities .invokeAndWait (() -> createAndShowGUI ());
5250
5351 robot .waitForIdle ();
52+ robot .delay (1000 );
5453
55- SwingUtilities .invokeAndWait (new Runnable () {
56-
57- @ Override
58- public void run () {
59- sbar .pressMouse ();
60- }
61- });
54+ SwingUtilities .invokeAndWait (() -> sbar .pressMouse ());
6255
6356 robot .waitForIdle ();
57+ robot .delay (200 );
6458
65- int value = getValue ();
66-
67- if (value != 9 ) {
68- throw new Error ("The scrollbar block increment is incorect" );
59+ if (getValue () != 9 ) {
60+ throw new RuntimeException ("The scrollbar block increment is incorrect" );
6961 }
7062 } finally {
7163 if (frame != null ) SwingUtilities .invokeAndWait (() -> frame .dispose ());
@@ -75,11 +67,8 @@ public void run() {
7567 private static int getValue () throws Exception {
7668 final int [] result = new int [1 ];
7769
78- SwingUtilities .invokeAndWait (new Runnable () {
79- @ Override
80- public void run () {
81- result [0 ] = sbar .getValue ();
82- }
70+ SwingUtilities .invokeAndWait (() -> {
71+ result [0 ] = sbar .getValue ();
8372 });
8473
8574 return result [0 ];
@@ -95,8 +84,9 @@ private static void createAndShowGUI() {
9584
9685 frame .getContentPane ().add (sbar );
9786 frame .pack ();
87+ frame .setLocationRelativeTo (null );
9888 frame .setVisible (true );
99-
89+ frame . toFront ();
10090 }
10191
10292 static class TestScrollBar extends JScrollBar {
@@ -111,7 +101,7 @@ public void pressMouse() {
111101 MouseEvent me = new MouseEvent (sbar ,
112102 MouseEvent .MOUSE_PRESSED ,
113103 (new Date ()).getTime (),
114- MouseEvent .BUTTON1_MASK ,
104+ MouseEvent .BUTTON1_DOWN_MASK ,
115105 3 * getWidth () / 4 , getHeight () / 2 ,
116106 1 , true );
117107 processMouseEvent (me );
0 commit comments