Skip to content

Commit c04c9ea

Browse files
author
Damon Nguyen
committed
8316627: JViewport Test headless failure
Reviewed-by: dcubed, prr
1 parent 5cacf21 commit c04c9ea

File tree

1 file changed

+10
-33
lines changed

1 file changed

+10
-33
lines changed

test/jdk/javax/swing/JViewport/bug4546474.java

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,46 +28,23 @@
2828
* @run main bug4546474
2929
*/
3030

31-
import java.awt.Dimension;
32-
import java.awt.Robot;
33-
3431
import javax.swing.JPanel;
3532
import javax.swing.JScrollBar;
3633
import javax.swing.JScrollPane;
37-
import javax.swing.SwingUtilities;
3834

3935
public class bug4546474 {
40-
static JScrollPane scrollpane;
41-
static JScrollBar sbar;
42-
static volatile boolean viewChanged;
36+
public static void main(String[] args) {
37+
JPanel panel = new JPanel();
38+
JScrollPane scrollpane = new JScrollPane(panel,
39+
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
40+
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
41+
JScrollBar sbar = scrollpane.getVerticalScrollBar();
4342

44-
public static void main(String[] args) throws Exception {
45-
SwingUtilities.invokeAndWait(() -> {
46-
JPanel panel = new JPanel();
47-
panel.setPreferredSize(new Dimension(500, 500));
48-
scrollpane = new JScrollPane(panel,
49-
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
50-
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
51-
sbar = scrollpane.getVerticalScrollBar();
52-
});
43+
scrollpane.setViewportView(null);
5344

54-
Robot robot = new Robot();
55-
robot.delay(500);
56-
SwingUtilities.invokeAndWait(() -> {
57-
sbar.addAdjustmentListener(e -> viewChanged = true);
58-
scrollpane.setViewportView(null);
59-
});
60-
robot.delay(500);
61-
if (!viewChanged) {
62-
viewChanged = true;
45+
if (sbar.getVisibleAmount() > 0) {
46+
throw new RuntimeException("Vertical scrollbar is not " +
47+
"updated when viewport is replaced");
6348
}
64-
robot.delay(500);
65-
66-
SwingUtilities.invokeAndWait(() -> {
67-
if (sbar.getVisibleAmount() > 0) {
68-
throw new RuntimeException("Vertical scrollbar is not " +
69-
"updated when viewport is replaced");
70-
}
71-
});
7249
}
7350
}

0 commit comments

Comments
 (0)