Java differentiate between menu click and accelerator
I have menu items with an accelerators. I would like to detect when a menu item was clicked as opposed to executed using accelerator. Is this possible?
While you can listen for MouseEVents and Actions, you can also just inspect the modifiers of the ActionEvent and see if a key was involved in the event or not. That way, you only have one listener to deal with...
a mouse click will fire off a MouseEvent and an Action. An accelerator will only fire off an action.
You can compare the key-info in the ActionEvent with the Action#ACCELERATOR_KEY key-value pair, which should be able to distinguish between a user clicking while holding a random/modifier key, and the actual accelerator key combination