45
45
* @library ../../regtesthelpers
46
46
* @build Util
47
47
* @run main bug8033069NoScrollBar
48
- * @author Alexey Ivanov
49
48
*/
50
- public class bug8033069NoScrollBar implements Runnable {
49
+ public class bug8033069NoScrollBar {
51
50
52
51
private static final String [] NO_SCROLL_ITEMS = new String [] {
53
52
"A" , "B" , "C" , "D" , "E" , "F"
@@ -61,6 +60,9 @@ public class bug8033069NoScrollBar implements Runnable {
61
60
private JComboBox cb1 ;
62
61
private JComboBox cb2 ;
63
62
63
+ private volatile Point p ;
64
+ private volatile Dimension d ;
65
+
64
66
public static void main (String [] args ) throws Exception {
65
67
iterateLookAndFeels (new bug8033069NoScrollBar (NO_SCROLL_ITEMS ));
66
68
}
@@ -98,24 +100,34 @@ private void setupUI() {
98
100
frame .add (panel );
99
101
100
102
frame .pack ();
103
+ frame .setLocationRelativeTo (null );
101
104
frame .setVisible (true );
102
105
}
103
106
107
+ private void disposeUI () {
108
+ if (frame != null ) {
109
+ frame .dispose ();
110
+ }
111
+ }
112
+
104
113
public void runTest () throws Exception {
105
114
try {
106
- SwingUtilities .invokeAndWait (this );
115
+ SwingUtilities .invokeAndWait (this :: setupUI );
107
116
108
117
robot .waitForIdle ();
109
118
assertFalse ("cb1 popup is visible" ,
110
119
Util .invokeOnEDT (cb1 ::isPopupVisible ));
111
120
112
121
// 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
+
115
127
robot .mouseMove (p .x + d .width / 2 , p .y + d .height / 2 );
116
128
// 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 );
119
131
120
132
robot .waitForIdle ();
121
133
assertTrue ("cb1 popup is not visible" ,
@@ -146,28 +158,24 @@ public void runTest() throws Exception {
146
158
147
159
148
160
// 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
+
151
166
robot .mouseMove (p .x + d .width / 2 , p .y + d .height / 2 );
152
167
153
168
robot .mouseWheel (1 );
154
169
robot .waitForIdle ();
155
170
assertFalse ("cb1 popup is visible after mouse wheel up on cb2" ,
156
171
Util .invokeOnEDT (cb1 ::isPopupVisible ));
157
172
} finally {
158
- if (frame != null ) {
159
- frame .dispose ();
160
- }
173
+ SwingUtilities .invokeAndWait (this ::disposeUI );
161
174
}
162
175
163
176
System .out .println ("Test passed" );
164
177
}
165
178
166
- @ Override
167
- public void run () {
168
- setupUI ();
169
- }
170
-
171
179
private static void assertTrue (String message , boolean value ) {
172
180
assertEquals (message , true , value );
173
181
}
0 commit comments