|
You can also add a keylistener to the button.
You have to import java.awt.event.*;
Set focus to button with JButton.requestFocus();
Code for keylistener normally in the constructor
JButton.addKeyListener( new KeyAdaptor()
{ public void keyPressed(KeyEvent e)
{ int key = e.getKeyCode();
if (key == KeyEvent.VK_ENTER)
{ statements or call method }
}
} );
|