Reputation: 4954
I'm developing a simple drawing application in Java. I'm restricted to using an AWT MenuBar (Not JMenuBar), and I need to set a few keyboard shortcuts and I can't find how to do so. I need shortcuts for two MenuItems and for three CheckBoxMenuItems.
It would go something like this:
newItem = Ctrl+N
quitItem = Ctrl+Q
rectangleItem = Ctrl+R
ovalItem = Ctrl+O
lineItem = Ctrl+L
Upvotes: 1
Views: 764
Reputation: 12795
Since the suggestion in the comments seems to have fixed at least part of your problem, I'm gonna put it here as an answer for users in the future.
Read the second half of this documentation and change your MenuItem
constructors to take in a MenuShortcut
as their second argument, like this (taken from the linked docs):
menu.add(new MenuItem("Save...", new MenuShortcut('s'));
Upvotes: 1
Reputation:
it would be easyer if:
put a layered pane? a glass in front, which will accept keyboard event in the whole area.
There you set the shortcuts.
Upvotes: 0