Jeremy
Jeremy

Reputation: 1364

Java: JMenuItem not working with ActionMap/AbstractAction

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?

Upvotes: 3

Views: 551

Answers (1)

user268396
user268396

Reputation: 11976

You are probably looking for the setAction() method (and maybe setActionCommand() as well).

Upvotes: 4

Related Questions