Generic code…
For some reason my JMenuItem is not performing actions.
I made a frame, a JMenuBar and a JMenuItem, everything is where it should be. I can click the JMenuItem just fine, it highlights and closes the menu properly but no action is performed.
I added a key to the ActionMap with the JMenuItems name. I also added a key to the Input map with the exact same name and it fires fine.
'menuitem'.setActionMap(getActionMap());
System.out.println('menuitemname'.getActionMap().size());
System.out.println('menuitemname'.getActionCommand());
returns 1 and the correct action key, respectively. Clicking the menu item does nothing. Is there something I’m missing?
You are probably looking for the
setAction()method (and maybesetActionCommand()as well).