Here you can find the source of registerKey(JComponent component, final int keyEvent, int modifiers, Action action)
public static void registerKey(JComponent component, final int keyEvent, int modifiers, Action action)
//package com.java2s; //License from project: Open Source License import javax.swing.*; public class Main { public static void registerKey(JComponent component, final int keyEvent, int modifiers, Action action) { final KeyStroke stroke = KeyStroke.getKeyStroke(keyEvent, modifiers); component.registerKeyboardAction(action, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW); }/*from w w w . jav a 2 s .c o m*/ }