Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to add shortcuts to Menu (not MenuItem) in JavaFX

I want to do menu like this (with shortcuts):

enter image description here

So, I did:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Menu fileMenu = new Menu("File");
fileMenu.setAccelerator(new KeyCodeCombination(KeyCode.F, KeyCombination.ALT_DOWN));

But it doesn’t work. When I press ALT+F nothing happens. Besides, I don’t know how to make key letters underlined. Can anyone say how to do it?

>Solution :

What you’re looking for is a "mnemonic", not an accelerator. Simply put an underscore (_) in front of the letter you want to use and ensure the mnemonicParsing property is set to true, which it is by default.

For example, the following:

Menu fileMenu = new Menu("_File");

Will let you use ALT+F to display the menu.

Note this works with MenuItem as well (Menu extends MenuItem). Adding a mnemonic to a MenuItem provides another way for your user to fire the item’s action (in addition to clicking it, using an accelerator, etc.).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading