Here you can find the source of addShortcut(JRootPane rootPane, String command, Action action, KeyStroke stroke)
public static void addShortcut(JRootPane rootPane, String command, Action action, KeyStroke stroke)
//package com.java2s; //License from project: Apache License import javax.swing.*; public class Main { public static void addShortcut(JRootPane rootPane, String command, Action action) { KeyStroke stroke = KeyStroke.getKeyStroke(command); addShortcut(rootPane, command, action, stroke); }//from ww w .ja v a 2 s. c o m public static void addShortcut(JRootPane rootPane, String command, Action action, KeyStroke stroke) { InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(stroke, command); rootPane.getActionMap().put(command, action); } }