Issue
In our JavaFX application, we use the System Menu property (useSystemMenuBarProperty) for MenuBar to create a more seamless JavaFX menu for Mac OS users.
We've noticed that keyboard accelerators linked to this MenuBar when in System Menu configuration cannot be single characters and looks like may need a Shortcut Down combination? In the example below the "D" shortcut action will never fire, but the "S" keycode plus shortcut down will fire.
My question would be is this intentional or a bug that anyone else has noticed ?
MenuBar menuBar = new MenuBar(new Menu("Example"));
MenuItem menuItem1 = new MenuItem("Test Menu Item");
menuItem1.setOnAction(action -> System.out.println("Menu 1 pressed"));
//This keyboard accelerator will never fire
menuItem1.setAccelerator(new KeyCodeCombination(KeyCode.D));
menuBar.getMenus().get(0).getItems().add(menuItem1);
MenuItem menuItem2 = new MenuItem("Test Menu Item 2");
//This accelerator will work as it has Shortcut Down added
menuItem2.setAccelerator(new KeyCodeCombination(KeyCode.S, KeyCombination.SHORTCUT_DOWN));
menuItem2.setOnAction(action -> System.out.println("Menu 2 pressed"));
menuBar.getMenus().get(0).getItems().add(menuItem2);
menuBar.setUseSystemMenuBar(true);
Solution
This is intentional... If you look at the actual menu shortcuts, you will never find just a single characters there. The reason is that menu is never focused, until activated, and single characters in many cases will be recognized as input into your UI instead of menu activation. Combinations of keys used for shortcuts, be it a menu or something else, are usually rarely used in editors or input fields combinations of characters and modifier keys(shift, control/command, alt/option), where character somehow corresponds to the operation, which makes it easier to remember. For example, Open - command-O, Get Info - command-I
Answered By - Eugene Ryzhikov
Answer Checked By - Clifford M. (JavaFixing Volunteer)