Overriding space key
import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JTextField; import javax.swing.KeyStroke; public class Main { public static void main(String[] argv) { JTextField component = new JTextField(10); component.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(new Character(' '), 0), "actionName"); JFrame f = new JFrame(); f.add(component); f.setSize(300, 300); f.setVisible(true); } }