I've recently added a console dialog to my program to make catching bugs easier. This is currently accessible through a JMenuItem and has keyboard shortcut 'Ctrl+L'.
Ideally I'd like to keep this option in but make the menu item hidden/invisible, because I only really want people to use it if they are copying the contents to me so I can investigate something. However, when I set the menu item to be invisible the shortcut also stops working.
Here's what I've tried:
mntmViewLogs.setAccelerator(KeyStroke.getKeyStroke('L', KeyEvent.CTRL_DOWN_MASK));
mntmViewLogs.setVisible(false);
Thanks!
解决方案
Set accelerator key not to menu, but to the action behind the menu:
getInputMap(WHEN_IN_FOCUSED_WINDOW).put(
acceleratorKey,
actionname);