Java Swing KeyStroke mapKeyStrokeToAction(final JComponent comp, final String ks, final String name, final AbstractAction action)

Here you can find the source of mapKeyStrokeToAction(final JComponent comp, final String ks, final String name, final AbstractAction action)

Description

Adds to JComponent action and keystroke for it.

License

Creative Commons License

Parameter

Parameter Description
comp JComponent
ks KeyStroke
name name
action action

Declaration

public static void mapKeyStrokeToAction(final JComponent comp, final String ks, final String name,
        final AbstractAction action) 

Method Source Code


//package com.java2s;

import javax.swing.AbstractAction;

import javax.swing.JComponent;
import javax.swing.KeyStroke;

public class Main {
    /**/*  w  ww .  j av  a 2  s  .com*/
     * Adds to JComponent action and keystroke for it.
     * 
     * @param comp JComponent
     * @param ks KeyStroke
     * @param name name
     * @param action action
     */
    public static void mapKeyStrokeToAction(final JComponent comp, final String ks, final String name,
            final AbstractAction action) {
        comp.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(ks), name);
        comp.getActionMap().put(name, action);
    }
}

Related

  1. installKeyBindings()
  2. installKeystrokes(JComponent component, Action... actions)
  3. isKeyStroke(String propClass)
  4. mapInput(JComponent component, int scope, final int keycode, final int modifiers, final AbstractAction action)
  5. mapKeyStrokeAction(JComponent component, String actionMapKey, Action action, KeyStroke keyStroke)
  6. mapKeyStrokeToButton(final JComponent comp, final String ks, final String name, final AbstractButton button)
  7. maybeInstall(InputMap map, String action, KeyStroke stroke)
  8. refleshAction(JComponent com, KeyStroke keyStroke)
  9. registerAction(JComponent comp, Action action, String key)