Java Swing KeyStroke addKeyboardAction(Action action, KeyStroke keyStroke, JComponent component)

Here you can find the source of addKeyboardAction(Action action, KeyStroke keyStroke, JComponent component)

Description

add Keyboard Action

License

EUPL

Declaration

public static void addKeyboardAction(Action action, KeyStroke keyStroke, JComponent component) 

Method Source Code


//package com.java2s;
/*/*from ww  w  .j  av a2s . c o m*/
 * Copyright 2011, 2012 Delving BV
 *
 *  Licensed under the EUPL, Version 1.0 or? as soon they
 *  will be approved by the European Commission - subsequent
 *  versions of the EUPL (the "Licence");
 *  you may not use this work except in compliance with the
 *  Licence.
 *  You may obtain a copy of the Licence at:
 *
 *  http://ec.europa.eu/idabc/eupl
 *
 *  Unless required by applicable law or agreed to in
 *  writing, software distributed under the Licence is
 *  distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 *  express or implied.
 *  See the Licence for the specific language governing
 *  permissions and limitations under the Licence.
 */

import javax.swing.*;

import static javax.swing.JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT;

public class Main {
    public static void addKeyboardAction(Action action, KeyStroke keyStroke, JComponent component) {
        String name = (String) action.getValue(Action.NAME);
        component.getActionMap().put(name, action);
        component.getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(keyStroke, name);
    }
}

Related

  1. addFocusBackKey(final int button)
  2. addFocusTraversalKey(final JComponent target, final int keyCode, final int modifiers, final int id)
  3. addHotKey(JComponent pane, Action action, KeyStroke key)
  4. addHotKey(JComponent pane, Action action, KeyStroke key)
  5. addKeyBinding(JComponent comp, KeyStroke key, String id, Action action)
  6. addKeyboardShortcut(final JComponent target, final AbstractButton button, final KeyStroke keyStroke)
  7. addShortcut(JRootPane rootPane, String command, Action action, KeyStroke stroke)
  8. addShortcutAction(String name, JComponent component, KeyStroke key, Action action)
  9. addShortcutToComponent(final JComponent component, final KeyStroke keystroke, final String actionCommand, final Action action)