Skip to content

Commit 9481fad

Browse files
author
Pankaj Bansal
committed
8163367: Test javax/swing/JComboBox/8033069/bug8033069NoScrollBar.java javax/swing/JComboBox/8033069/bug8033069ScrollBar.java fails intermittently
Reviewed-by: aivanov
1 parent 9adbf15 commit 9481fad

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

test/jdk/ProblemList.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,6 @@ javax/swing/JWindow/ShapedAndTranslucentWindows/PerPixelTranslucentSwing.java 81
738738
javax/swing/JWindow/ShapedAndTranslucentWindows/SetShapeAndClickSwing.java 8013450 macosx-all
739739
javax/swing/JWindow/ShapedAndTranslucentWindows/TranslucentJComboBox.java 8024627 macosx-all
740740
# The next test below is an intermittent failure
741-
javax/swing/JComboBox/8033069/bug8033069ScrollBar.java 8163367 generic-all
742741
javax/swing/JTree/DnD/LastNodeLowerHalfDrop.java 8159131 linux-all
743742
javax/swing/JTree/4633594/JTreeFocusTest.java 8173125 macosx-all
744743
javax/swing/AbstractButton/6711682/bug6711682.java 8060765 windows-all,macosx-all

test/jdk/javax/swing/JComboBox/8033069/bug8033069NoScrollBar.java

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@
4545
* @library ../../regtesthelpers
4646
* @build Util
4747
* @run main bug8033069NoScrollBar
48-
* @author Alexey Ivanov
4948
*/
50-
public class bug8033069NoScrollBar implements Runnable {
49+
public class bug8033069NoScrollBar {
5150

5251
private static final String[] NO_SCROLL_ITEMS = new String[] {
5352
"A", "B", "C", "D", "E", "F"
@@ -61,6 +60,9 @@ public class bug8033069NoScrollBar implements Runnable {
6160
private JComboBox cb1;
6261
private JComboBox cb2;
6362

63+
private volatile Point p;
64+
private volatile Dimension d;
65+
6466
public static void main(String[] args) throws Exception {
6567
iterateLookAndFeels(new bug8033069NoScrollBar(NO_SCROLL_ITEMS));
6668
}
@@ -98,24 +100,34 @@ private void setupUI() {
98100
frame.add(panel);
99101

100102
frame.pack();
103+
frame.setLocationRelativeTo(null);
101104
frame.setVisible(true);
102105
}
103106

107+
private void disposeUI() {
108+
if (frame != null) {
109+
frame.dispose();
110+
}
111+
}
112+
104113
public void runTest() throws Exception {
105114
try {
106-
SwingUtilities.invokeAndWait(this);
115+
SwingUtilities.invokeAndWait(this::setupUI);
107116

108117
robot.waitForIdle();
109118
assertFalse("cb1 popup is visible",
110119
Util.invokeOnEDT(cb1::isPopupVisible));
111120

112121
// Move mouse pointer to the center of the fist combo box
113-
Point p = cb1.getLocationOnScreen();
114-
Dimension d = cb1.getSize();
122+
SwingUtilities.invokeAndWait(() -> {
123+
p = cb1.getLocationOnScreen();
124+
d = cb1.getSize();
125+
});
126+
115127
robot.mouseMove(p.x + d.width / 2, p.y + d.height / 2);
116128
// Click it to open popup
117-
robot.mousePress(InputEvent.BUTTON1_MASK);
118-
robot.mouseRelease(InputEvent.BUTTON1_MASK);
129+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
130+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
119131

120132
robot.waitForIdle();
121133
assertTrue("cb1 popup is not visible",
@@ -146,28 +158,24 @@ public void runTest() throws Exception {
146158

147159

148160
// Move mouse pointer to the center of the second combo box
149-
p = cb2.getLocationOnScreen();
150-
d = cb2.getSize();
161+
SwingUtilities.invokeAndWait(() -> {
162+
p = cb2.getLocationOnScreen();
163+
d = cb2.getSize();
164+
});
165+
151166
robot.mouseMove(p.x + d.width / 2, p.y + d.height / 2);
152167

153168
robot.mouseWheel(1);
154169
robot.waitForIdle();
155170
assertFalse("cb1 popup is visible after mouse wheel up on cb2",
156171
Util.invokeOnEDT(cb1::isPopupVisible));
157172
} finally {
158-
if (frame != null) {
159-
frame.dispose();
160-
}
173+
SwingUtilities.invokeAndWait(this::disposeUI);
161174
}
162175

163176
System.out.println("Test passed");
164177
}
165178

166-
@Override
167-
public void run() {
168-
setupUI();
169-
}
170-
171179
private static void assertTrue(String message, boolean value) {
172180
assertEquals(message, true, value);
173181
}

0 commit comments

Comments
 (0)