|
28 | 28 | * @run main bug4546474 |
29 | 29 | */ |
30 | 30 |
|
31 | | -import java.awt.Dimension; |
32 | | -import java.awt.Robot; |
33 | | - |
34 | 31 | import javax.swing.JPanel; |
35 | 32 | import javax.swing.JScrollBar; |
36 | 33 | import javax.swing.JScrollPane; |
37 | | -import javax.swing.SwingUtilities; |
38 | 34 |
|
39 | 35 | 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(); |
43 | 42 |
|
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); |
53 | 44 |
|
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"); |
63 | 48 | } |
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 | | - }); |
72 | 49 | } |
73 | 50 | } |
0 commit comments