1 /* |
1 /* |
2 * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
24 /* |
24 /* |
25 * @test |
25 * @test |
26 * @key headful |
26 * @key headful |
27 * @library ../../regtesthelpers |
27 * @library ../../regtesthelpers |
28 * @build Util |
28 * @build Util |
29 * @bug 8033699 8154043 8167160 8208640 |
29 * @bug 8033699 8154043 8167160 8208640 8226892 |
30 * @summary Incorrect radio button behavior when pressing tab key |
30 * @summary Incorrect radio button behavior when pressing tab key |
31 * @run main bug8033699 |
31 * @run main bug8033699 |
32 */ |
32 */ |
33 import java.awt.KeyboardFocusManager; |
33 import java.awt.KeyboardFocusManager; |
34 import java.awt.Robot; |
34 import java.awt.Robot; |
|
35 import java.awt.event.ActionListener; |
35 import java.awt.event.KeyEvent; |
36 import java.awt.event.KeyEvent; |
36 import java.util.logging.Level; |
37 import java.util.logging.Level; |
37 import java.util.logging.Logger; |
38 import java.util.logging.Logger; |
38 import javax.swing.BorderFactory; |
39 import javax.swing.BorderFactory; |
39 import javax.swing.BoxLayout; |
40 import javax.swing.BoxLayout; |
91 runTest7(); |
92 runTest7(); |
92 |
93 |
93 // down key circle back to first button in grouped radio button |
94 // down key circle back to first button in grouped radio button |
94 runTest8(); |
95 runTest8(); |
95 |
96 |
|
97 // Verify that ActionListener is called when a RadioButton is selected using arrow key. |
|
98 runTest9(); |
|
99 |
96 SwingUtilities.invokeAndWait(() -> mainFrame.dispose()); |
100 SwingUtilities.invokeAndWait(() -> mainFrame.dispose()); |
97 } |
101 } |
98 |
102 |
99 private static void changeLAF() { |
103 private static void changeLAF() { |
100 String currentLAF = UIManager.getLookAndFeel().toString(); |
104 String currentLAF = UIManager.getLookAndFeel().toString(); |
243 throw new RuntimeException("Focus is not on Radio Button Single as Expected"); |
247 throw new RuntimeException("Focus is not on Radio Button Single as Expected"); |
244 } |
248 } |
245 }); |
249 }); |
246 } |
250 } |
247 |
251 |
|
252 private static Boolean actRB1 = false; |
|
253 private static Boolean actRB2 = false; |
|
254 private static Boolean actRB3 = false; |
|
255 |
|
256 // JDK-8226892: Verify that ActionListener is called when a RadioButton is selected using arrow key. |
|
257 private static void runTest9() throws Exception { |
|
258 SwingUtilities.invokeAndWait(() -> { |
|
259 radioBtn1.setSelected(true); |
|
260 radioBtn1.requestFocusInWindow(); |
|
261 }); |
|
262 |
|
263 ActionListener actLrRB1 = e -> actRB1 = true; |
|
264 ActionListener actLrRB2 = e -> actRB2 = true; |
|
265 ActionListener actLrRB3 = e -> actRB3 = true; |
|
266 |
|
267 radioBtn1.addActionListener(actLrRB1); |
|
268 radioBtn2.addActionListener(actLrRB2); |
|
269 radioBtn3.addActionListener(actLrRB3); |
|
270 |
|
271 hitKey(robot, KeyEvent.VK_DOWN); |
|
272 hitKey(robot, KeyEvent.VK_DOWN); |
|
273 hitKey(robot, KeyEvent.VK_DOWN); |
|
274 |
|
275 String failMessage = "ActionListener not invoked when selected using arrow key."; |
|
276 if (!actRB2) { |
|
277 throw new RuntimeException("RadioButton 2: " + failMessage); |
|
278 } |
|
279 if (!actRB3) { |
|
280 throw new RuntimeException("RadioButton 3: " + failMessage); |
|
281 } |
|
282 if (!actRB1) { |
|
283 throw new RuntimeException("RadioButton 1: " + failMessage); |
|
284 } |
|
285 |
|
286 radioBtn1.removeActionListener(actLrRB1); |
|
287 radioBtn2.removeActionListener(actLrRB2); |
|
288 radioBtn3.removeActionListener(actLrRB3); |
|
289 } |
|
290 |
248 private static void hitKey(Robot robot, int keycode) { |
291 private static void hitKey(Robot robot, int keycode) { |
249 robot.keyPress(keycode); |
292 robot.keyPress(keycode); |
250 robot.keyRelease(keycode); |
293 robot.keyRelease(keycode); |
251 robot.waitForIdle(); |
294 robot.waitForIdle(); |
252 } |
295 } |