Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8237505: RadioMenuItem in ToggleGroup: deselected on accelerator #1002

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -174,8 +174,13 @@ private static void doAcceleratorInstall(final List<? extends MenuItem> items, f
Event.fireEvent(target, new Event(MenuItem.MENU_VALIDATION_EVENT));
}
if (!menuitem.isDisable()) {
if (menuitem instanceof RadioMenuItem) {
((RadioMenuItem)menuitem).setSelected(!((RadioMenuItem)menuitem).isSelected());
if (menuitem instanceof RadioMenuItem radioMenuItem) {
if (radioMenuItem.getToggleGroup() == null) {
radioMenuItem.setSelected(!radioMenuItem.isSelected());
}
else {
radioMenuItem.setSelected(true);
}
}
else if (menuitem instanceof CheckMenuItem) {
((CheckMenuItem)menuitem).setSelected(!((CheckMenuItem)menuitem).isSelected());
Expand Down
Expand Up @@ -28,6 +28,9 @@
import static test.com.sun.javafx.scene.control.infrastructure.ControlTestUtils.*;

import test.com.sun.javafx.pgstub.StubToolkit;
import test.com.sun.javafx.scene.control.infrastructure.KeyEventFirer;
import test.com.sun.javafx.scene.control.infrastructure.KeyModifier;
import test.com.sun.javafx.scene.control.infrastructure.StageLoader;
import com.sun.javafx.tk.Toolkit;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ObjectProperty;
Expand All @@ -36,8 +39,13 @@
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.RadioMenuItem;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.input.KeyCombination;
import javafx.scene.input.KeyCode;
import javafx.scene.shape.Rectangle;
import static org.junit.Assert.*;

Expand Down Expand Up @@ -296,4 +304,26 @@ public class RadioMenuItemTest {
assertTrue(b1.isSelected());
assertFalse(result8189677);
}

@Test public void testRadioMenuItemSelectionOnAccelerator() {
MenuBar menuBar = new MenuBar();
Menu menu = new Menu("Submenu");
menuBar.getMenus().add(menu);

ToggleGroup group = new ToggleGroup();
RadioMenuItem radioMenuItem = new RadioMenuItem("ONE");
radioMenuItem.setToggleGroup(group);
radioMenuItem.setAccelerator(KeyCombination.valueOf("alt+1"));
menu.getItems().add(radioMenuItem);

StageLoader s = new StageLoader(menuBar);
Scene scene = s.getStage().getScene();
KeyEventFirer keyboard = new KeyEventFirer(radioMenuItem, scene);

keyboard.doKeyPress(KeyCode.DIGIT1, KeyModifier.ALT);
assertTrue(radioMenuItem.isSelected());

keyboard.doKeyPress(KeyCode.DIGIT1, KeyModifier.ALT);
assertTrue(radioMenuItem.isSelected());
}
}