11/*
2- * Copyright (c) 2011, 2024 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2011, 2025 , 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
2323
2424/*
2525 * @test
26- * @key headful
2726 * @bug 4865918
27+ * @requires (os.family != "mac")
2828 * @summary REGRESSION:JCK1.4a-runtime api/javax_swing/interactive/JScrollBarTests.html#JScrollBar
2929 * @run main bug4865918
3030 */
3131
3232import java .awt .Dimension ;
33- import java .awt .Robot ;
3433import java .awt .event .MouseAdapter ;
3534import java .awt .event .MouseEvent ;
36- import javax .swing .JFrame ;
3735import javax .swing .JScrollBar ;
3836import javax .swing .SwingUtilities ;
3937import java .util .concurrent .CountDownLatch ;
4442public class bug4865918 {
4543
4644 private static TestScrollBar sbar ;
47- private static JFrame frame ;
4845 private static final CountDownLatch mousePressLatch = new CountDownLatch (1 );
4946
5047 public static void main (String [] argv ) throws Exception {
51- try {
52- Robot robot = new Robot ();
53- SwingUtilities .invokeAndWait (() -> createAndShowGUI ());
54-
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- }
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 ());
6254
63- robot .waitForIdle ();
64- robot .delay (200 );
55+ SwingUtilities .invokeAndWait (() -> sbar .pressMouse ());
56+ if (!mousePressLatch .await (2 , TimeUnit .SECONDS )) {
57+ throw new RuntimeException ("Timed out waiting for mouse press" );
58+ }
6559
66- if (getValue () != 9 ) {
67- throw new RuntimeException ("The scrollbar block increment is incorrect" );
68- }
69- } finally {
70- if (frame != null ) SwingUtilities .invokeAndWait (() -> frame .dispose ());
60+ if (getValue () != 9 ) {
61+ throw new RuntimeException ("The scrollbar block increment is incorrect" );
7162 }
7263 }
7364
@@ -78,12 +69,11 @@ private static int getValue() throws Exception {
7869 result [0 ] = sbar .getValue ();
7970 });
8071
72+ System .out .println ("value " + result [0 ]);
8173 return result [0 ];
8274 }
8375
84- private static void createAndShowGUI () {
85- frame = new JFrame ("bug4865918" );
86- frame .setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
76+ private static void setupTest () {
8777
8878 sbar = new TestScrollBar (JScrollBar .HORIZONTAL , -1 , 10 , -100 , 100 );
8979 sbar .setPreferredSize (new Dimension (200 , 20 ));
@@ -94,11 +84,6 @@ public void mousePressed(MouseEvent e) {
9484 }
9585 });
9686
97- frame .getContentPane ().add (sbar );
98- frame .pack ();
99- frame .setLocationRelativeTo (null );
100- frame .setVisible (true );
101- frame .toFront ();
10287 }
10388
10489 static class TestScrollBar extends JScrollBar {
0 commit comments