Here you can find the source of enableEnter(JButton b)
public static void enableEnter(JButton b)
//package com.java2s; // License: GPL. For details, see LICENSE file. import java.awt.event.KeyEvent; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.KeyStroke; public class Main { /**/*from w ww . j a va2s.c om*/ * Enable activating button on Enter (which is replaced with spacebar for certain Look-And-Feels) */ public static void enableEnter(JButton b) { b.setFocusable(true); b.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter"); b.getActionMap().put("enter", b.getAction()); } }