Reputation: 3119
I have a context menu in my program. I would like to show the keys that perform the same function as the context menu. I would like to have the name of the menu left justified, and the key command right justified. I don't have a screenshot, but here is a drawing:
How things are now (Simplified)
Play (↵)
Stop (X)
Enqueue (Q)
Browse Folder (B)
How I'd like things to be
Play (↵)
Stop (X)
Enqueue (Q)
Browse Folder (B)
My code is just boilerplate javafx context menu code:
ContextMenu contextMenu = new ContextMenu();
MenuItem playMenuItem = new MenuItem( "Play (↵)" );
MenuItem queueMenuItem = new MenuItem( "Enqueue (Q)" );
MenuItem cropMenuItem = new MenuItem( "Crop (⇧␡)" );
MenuItem deleteMenuItem = new MenuItem( "Delete (␡)" );
MenuItem browseMenuItem = new MenuItem( "Browse Folder (B)" );
Is there any way to put two labels on a context menu, or have one float some text right?
Thanks!
Upvotes: 0
Views: 295
Reputation: 1912
I think you can avoid this problem completely by using accelerators. (Which is what those are meant for I guese?) For example:
ContextMenu contextMenu = new ContextMenu();
MenuItem playMenuItem = new MenuItem( "Play" );
playMenuItem.setAccelerator(new KeyCodeCombination(KeyCode.ENTER));
//etc.
This wil not only take care of the acceleration for you, but it will also display the acceleration keys in a simular way you are trying to achieve at the moment with plain Strings.
Upvotes: 1