I have an Action
SampleAction a = new SampleAction("foo", null);
Then I add it to a Button, and to an ActionMap
JButton b = new JButton(a);
b.getActionMap().put("bar", a);
b.getInputMap().put(KeyStroke.getKeyStroke("F1"), "bar");
I put a trace (System.out.println("Action [" + e.getActionCommand() + "] performed!");
) inside the Action. When I press the button with mouse it shows
Action [foo] performed!
But when i use F1, it shows:
Action [null] performed!
Why?
class SampleAction extends AbstractAction
{
public SampleAction(String text, Icon icon) {
super(text, icon);
}
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("Action [" + e.getActionCommand() + "] performed!");
}
}