Skip to content

Commit

Permalink
Backport 9fafd63d46f64428e0b9c2e9a6b0ac7ca0e2d355
Browse files Browse the repository at this point in the history
  • Loading branch information
GoeLin committed Feb 20, 2025
1 parent 6f785a6 commit 1255ae4
Showing 1 changed file with 16 additions and 31 deletions.
47 changes: 16 additions & 31 deletions test/jdk/javax/swing/JScrollBar/4865918/bug4865918.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -23,17 +23,15 @@

/*
* @test
* @key headful
* @bug 4865918
* @requires (os.family != "mac")
* @summary REGRESSION:JCK1.4a-runtime api/javax_swing/interactive/JScrollBarTests.html#JScrollBar
* @run main bug4865918
*/

import java.awt.Dimension;
import java.awt.Robot;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JScrollBar;
import javax.swing.SwingUtilities;
import java.util.concurrent.CountDownLatch;
Expand All @@ -44,30 +42,23 @@
public class bug4865918 {

private static TestScrollBar sbar;
private static JFrame frame;
private static final CountDownLatch mousePressLatch = new CountDownLatch(1);

public static void main(String[] argv) throws Exception {
try {
Robot robot = new Robot();
SwingUtilities.invokeAndWait(() -> createAndShowGUI());

robot.waitForIdle();
robot.delay(1000);

SwingUtilities.invokeAndWait(() -> sbar.pressMouse());
if (!mousePressLatch.await(2, TimeUnit.SECONDS)) {
throw new RuntimeException("Timed out waiting for mouse press");
}
String osName = System.getProperty("os.name");
if (osName.toLowerCase().contains("os x")) {
System.out.println("This test is not for MacOS, considered passed.");
return;
}
SwingUtilities.invokeAndWait(() -> setupTest());

robot.waitForIdle();
robot.delay(200);
SwingUtilities.invokeAndWait(() -> sbar.pressMouse());
if (!mousePressLatch.await(2, TimeUnit.SECONDS)) {
throw new RuntimeException("Timed out waiting for mouse press");
}

if (getValue() != 9) {
throw new RuntimeException("The scrollbar block increment is incorrect");
}
} finally {
if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());
if (getValue() != 9) {
throw new RuntimeException("The scrollbar block increment is incorrect");
}
}

Expand All @@ -78,12 +69,11 @@ private static int getValue() throws Exception {
result[0] = sbar.getValue();
});

System.out.println("value " + result[0]);
return result[0];
}

private static void createAndShowGUI() {
frame = new JFrame("bug4865918");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
private static void setupTest() {

sbar = new TestScrollBar(JScrollBar.HORIZONTAL, -1, 10, -100, 100);
sbar.setPreferredSize(new Dimension(200, 20));
Expand All @@ -94,11 +84,6 @@ public void mousePressed(MouseEvent e) {
}
});

frame.getContentPane().add(sbar);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.toFront();
}

static class TestScrollBar extends JScrollBar {
Expand Down

0 comments on commit 1255ae4

Please sign in to comment.