Here you can find the source of addHotKey(JComponent pane, Action action, KeyStroke key)
public static void addHotKey(JComponent pane, Action action, KeyStroke key)
//package com.java2s; import javax.swing.Action; import javax.swing.JComponent; import javax.swing.KeyStroke; public class Main { /** JDK1.2 doesn't have this string defined in javax.swing.Action. * This is the value that JDK1.3 uses. *///from w w w .j a v a2 s . c o m public static final String ACCELERATOR_KEY = "AcceleratorKey"; /** Add a quick keystroke on the given pane for the given action. * The keystroke that is added is given in the ACCELERATOR_KEY * property that has been set in the action. If the ACCELERATOR_KEY * property has not been set, then do not add a hotkey. */ public static void addHotKey(JComponent pane, Action action) { addHotKey(pane, action, null); } /** Add a quick keystroke on the given pane for the given action. * If the given keystroke is null, then use the ACCELERATOR_KEY * property that has been set in the action. If the given keystroke * is null, Otherwise, set the * ACCELERATOR_KEY property to the given key stroke. */ public static void addHotKey(JComponent pane, Action action, KeyStroke key) { String name = (String) action.getValue(action.NAME); if (key == null) { key = (KeyStroke) action.getValue(ACCELERATOR_KEY); } else { action.putValue(ACCELERATOR_KEY, key); } if (key != null) pane.registerKeyboardAction(action, name, key, pane.WHEN_IN_FOCUSED_WINDOW); } }