Reputation: 1873
I have a program which I want to use keybindings:
// Imports..
public class Test{
JButton button = new JButton();
Test(){
//...
button.getInputMap().put(KeyStroke.getKeyStroke("A"), "A");
button.getActionMap().put("Action", action);
//...
}
}
Now how do I make the button respond when it is clicked?
Is it like KeyListeners where I have an actionPerformed method?
Upvotes: 1
Views: 104
Reputation: 109823
Now how do I make the button respond when it is clicked?
from KeyBindings is there only one way
button.doClick();
then this code line to invoke ActionListener or Swing Action added to the JButton
Upvotes: 3
Reputation: 168845
Is it like KeyListeners where I have an actionPerformed method?
A KeyListener
has no actionPerformed
method! The solution is to add an ActionListener
, or as @mKorbel points out, create the button using an Action
.
Upvotes: 3