Java JRootPane addShortcut(JRootPane rootPane, String command, Action action)

Here you can find the source of addShortcut(JRootPane rootPane, String command, Action action)

Description

add Shortcut

License

Apache License

Declaration

public static void addShortcut(JRootPane rootPane, String command, Action action) 

Method Source Code

//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   w  ww  .j a  va  2 s  .co  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);
    }
}

Related

  1. closeOnEscape(final Window window, final JRootPane root)
  2. getRootPane(Window window)
  3. installEscapeBinding(final Window window, final JRootPane rootPane, final boolean dispose)
  4. isSecondaryWindow(JRootPane rp)