@Override protected void processComponentKeyEvent(final KeyEvent e){
  if (e.getKeyCode() == KeyEvent.VK_SPACE || e.getKeyCode() == KeyEvent.VK_ENTER) {
    e.consume();
    notifyActionListeners();
  }
}

@ Override protected void processComponentKeyEvent ( final KeyEvent e ) { if ( e . getKeyCode ( ) == KeyEvent . VK_SPACE || e . getKeyCode ( ) == KeyEvent . VK_ENTER ) { e . consume ( ) ; notifyActionListeners ( ) ; } }
we are overriding this method to handle the space bar and enter key events . these key events will trigger the actionperformed method on all listeners .
