Java Swing KeyStroke registerKeyBoardAction(JComponent comp, Action action, KeyStroke stroke)

Here you can find the source of registerKeyBoardAction(JComponent comp, Action action, KeyStroke stroke)

Description

register Key Board Action

License

Open Source License

Declaration

public static void registerKeyBoardAction(JComponent comp, Action action, KeyStroke stroke) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static void registerKeyBoardAction(JComponent comp, Action action) {
        registerKeyBoardAction(comp, action, JComponent.WHEN_IN_FOCUSED_WINDOW);
    }//from  ww w. j  av a  2s .  c  o m

    public static void registerKeyBoardAction(JComponent comp, Action action, KeyStroke stroke) {
        comp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(stroke, action.getValue(Action.NAME));
        comp.getActionMap().put(action.getValue(Action.NAME), action);
    }

    /**
     * 
     * @param comp
     * @param action
     * @param condition - see {@link JComponent}
     * (WHEN_FOCUSED, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,WHEN_IN_FOCUSED_WINDOW)
     */
    public static void registerKeyBoardAction(JComponent comp, Action action, int condition) {
        comp.getInputMap(condition).put((KeyStroke) action.getValue(Action.ACCELERATOR_KEY),
                action.getValue(Action.NAME));
        comp.getActionMap().put(action.getValue(Action.NAME), action);
    }
}

Related

  1. refleshAction(JComponent com, KeyStroke keyStroke)
  2. registerAction(JComponent comp, Action action, String key)
  3. registerAction(JComponent component, int condition, KeyStroke key, Action action, String command)
  4. registerAsAction(final KeyStroke keyStroke, final String actionKey, final Runnable action, final JComponent component)
  5. registerKeyBinding(final JComponent aComponent, final String aKeyStroke, final Action aAction)
  6. registerKeyHandler(JComponent component, KeyStroke stroke, final ActionListener listener, final String actionCommand)
  7. registerKeystroke(final JComponent aComponent, final Action aAction, final String aCommandName)
  8. registerTabKey(Container container)
  9. removeAcceleratorFromChildren(Container container, KeyStroke accelerator)