Skip to content

Commit

Permalink
8316627: JViewport Test headless failure
Browse files Browse the repository at this point in the history
Reviewed-by: dcubed, prr
  • Loading branch information
Damon Nguyen committed Sep 20, 2023
1 parent 5cacf21 commit c04c9ea
Showing 1 changed file with 10 additions and 33 deletions.
43 changes: 10 additions & 33 deletions test/jdk/javax/swing/JViewport/bug4546474.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,46 +28,23 @@
* @run main bug4546474
*/

import java.awt.Dimension;
import java.awt.Robot;

import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;

public class bug4546474 {
static JScrollPane scrollpane;
static JScrollBar sbar;
static volatile boolean viewChanged;
public static void main(String[] args) {
JPanel panel = new JPanel();
JScrollPane scrollpane = new JScrollPane(panel,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
JScrollBar sbar = scrollpane.getVerticalScrollBar();

public static void main(String[] args) throws Exception {
SwingUtilities.invokeAndWait(() -> {
JPanel panel = new JPanel();
panel.setPreferredSize(new Dimension(500, 500));
scrollpane = new JScrollPane(panel,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
sbar = scrollpane.getVerticalScrollBar();
});
scrollpane.setViewportView(null);

Robot robot = new Robot();
robot.delay(500);
SwingUtilities.invokeAndWait(() -> {
sbar.addAdjustmentListener(e -> viewChanged = true);
scrollpane.setViewportView(null);
});
robot.delay(500);
if (!viewChanged) {
viewChanged = true;
if (sbar.getVisibleAmount() > 0) {
throw new RuntimeException("Vertical scrollbar is not " +
"updated when viewport is replaced");
}
robot.delay(500);

SwingUtilities.invokeAndWait(() -> {
if (sbar.getVisibleAmount() > 0) {
throw new RuntimeException("Vertical scrollbar is not " +
"updated when viewport is replaced");
}
});
}
}

3 comments on commit c04c9ea

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dcubed-ojdk
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/tag jdk-22+16

@openjdk
Copy link

@openjdk openjdk bot commented on c04c9ea Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dcubed-ojdk The tag jdk-22+16 was successfully created.

Please sign in to comment.