提交 371694d6 编写于 作者: A arapte

8226892: ActionListeners on JRadioButtons don't get notified when selection is...

8226892: ActionListeners on JRadioButtons don't get notified when selection is changed with arrow keys
Reviewed-by: serb, psadhukhan
上级 47c766f0
/* /*
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -531,8 +531,13 @@ public class BasicRadioButtonUI extends BasicToggleButtonUI ...@@ -531,8 +531,13 @@ public class BasicRadioButtonUI extends BasicToggleButtonUI
} }
if (newSelectedBtn != null && if (newSelectedBtn != null &&
(newSelectedBtn != activeBtn)) { (newSelectedBtn != activeBtn)) {
ButtonModel btnModel = newSelectedBtn.getModel();
btnModel.setPressed(true);
btnModel.setArmed(true);
newSelectedBtn.requestFocusInWindow(); newSelectedBtn.requestFocusInWindow();
newSelectedBtn.setSelected(true); newSelectedBtn.setSelected(true);
btnModel.setPressed(false);
btnModel.setArmed(false);
} }
} }
} }
......
/* /*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
* @test * @test
* @library ../../regtesthelpers * @library ../../regtesthelpers
* @build Util * @build Util
* @bug 8033699 * @bug 8033699 8226892
* @summary Incorrect radio button behavior when pressing tab key * @summary Incorrect radio button behavior when pressing tab key
* @author Vivi An * @author Vivi An
* @run main bug8033699 * @run main bug8033699
...@@ -86,6 +86,9 @@ public class bug8033699 { ...@@ -86,6 +86,9 @@ public class bug8033699 {
// down key circle back to first button in grouped radio button // down key circle back to first button in grouped radio button
runTest8(); runTest8();
// Verify that ActionListener is called when a RadioButton is selected using arrow key.
runTest9();
} }
private static void createAndShowGUI() { private static void createAndShowGUI() {
...@@ -239,6 +242,45 @@ public class bug8033699 { ...@@ -239,6 +242,45 @@ public class bug8033699 {
}); });
} }
private static Boolean actRB1 = false;
private static Boolean actRB2 = false;
private static Boolean actRB3 = false;
// JDK-8226892: Verify that ActionListener is called when a RadioButton is selected using arrow key.
private static void runTest9() throws Exception {
SwingUtilities.invokeAndWait(() -> {
radioBtn1.setSelected(true);
radioBtn1.requestFocusInWindow();
});
ActionListener actLrRB1 = e -> actRB1 = true;
ActionListener actLrRB2 = e -> actRB2 = true;
ActionListener actLrRB3 = e -> actRB3 = true;
radioBtn1.addActionListener(actLrRB1);
radioBtn2.addActionListener(actLrRB2);
radioBtn3.addActionListener(actLrRB3);
hitKey(robot, KeyEvent.VK_DOWN);
hitKey(robot, KeyEvent.VK_DOWN);
hitKey(robot, KeyEvent.VK_DOWN);
String failMessage = "ActionListener not invoked when selected using arrow key.";
if (!actRB2) {
throw new RuntimeException("RadioButton 2: " + failMessage);
}
if (!actRB3) {
throw new RuntimeException("RadioButton 3: " + failMessage);
}
if (!actRB1) {
throw new RuntimeException("RadioButton 1: " + failMessage);
}
radioBtn1.removeActionListener(actLrRB1);
radioBtn2.removeActionListener(actLrRB2);
radioBtn3.removeActionListener(actLrRB3);
}
private static void hitKey(Robot robot, int keycode) { private static void hitKey(Robot robot, int keycode) {
robot.keyPress(keycode); robot.keyPress(keycode);
robot.keyRelease(keycode); robot.keyRelease(keycode);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册