Java Swing KeyStroke addShortcut(JRootPane rootPane, String command, Action action, KeyStroke stroke)

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

Description

add Shortcut

License

Apache License

Declaration

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

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 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);
    }
}

Related

  1. addHotKey(JComponent pane, Action action, KeyStroke key)
  2. addHotKey(JComponent pane, Action action, KeyStroke key)
  3. addKeyBinding(JComponent comp, KeyStroke key, String id, Action action)
  4. addKeyboardAction(Action action, KeyStroke keyStroke, JComponent component)
  5. addKeyboardShortcut(final JComponent target, final AbstractButton button, final KeyStroke keyStroke)
  6. addShortcutAction(String name, JComponent component, KeyStroke key, Action action)
  7. addShortcutToComponent(final JComponent component, final KeyStroke keystroke, final String actionCommand, final Action action)
  8. addShortcutToComponent(JComponent component, KeyStroke keystroke, String actionCommand, Action action)
  9. bindAction(JComponent aComponent, String aCommand, Action anAction, KeyStroke aKeyStroke)