Java Swing KeyStroke registerAction(JComponent comp, Action action, String key)

Here you can find the source of registerAction(JComponent comp, Action action, String key)

Description

Register action with the input map.

License

Open Source License

Parameter

Parameter Description
comp the JComponent on which to register the action
action the Action to register
key the key to register the action with. This has to be a unique string that identifies the action to the system.

Declaration

static public void registerAction(JComponent comp, Action action, String key) 

Method Source Code


//package com.java2s;
/*/*from w w w.j  ava  2s  .  c  om*/
* Copyright (c) 2000 - 2005 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:  
 *
*/

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

public class Main {
    /**
     * Register action with the input map. Depends on the Action.ACCELERATOR_KEY
     * property being set in the action.
     * @param comp the JComponent on which to register the action
     * @param action the Action to register
     * @param key the key to register the action with. This has to be a unique
     * string that identifies the action to the system.
     */
    static public void registerAction(JComponent comp, Action action, String key) {
        KeyStroke ks = (KeyStroke) action.getValue(Action.ACCELERATOR_KEY);
        if (ks != null) {
            comp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ks, key);
            comp.getActionMap().put(key, action);
        }
    }
}

Related

  1. mapKeyStrokeAction(JComponent component, String actionMapKey, Action action, KeyStroke keyStroke)
  2. mapKeyStrokeToAction(final JComponent comp, final String ks, final String name, final AbstractAction action)
  3. mapKeyStrokeToButton(final JComponent comp, final String ks, final String name, final AbstractButton button)
  4. maybeInstall(InputMap map, String action, KeyStroke stroke)
  5. refleshAction(JComponent com, KeyStroke keyStroke)
  6. registerAction(JComponent component, int condition, KeyStroke key, Action action, String command)
  7. registerAsAction(final KeyStroke keyStroke, final String actionKey, final Runnable action, final JComponent component)
  8. registerKeyBinding(final JComponent aComponent, final String aKeyStroke, final Action aAction)
  9. registerKeyBoardAction(JComponent comp, Action action, KeyStroke stroke)