Here you can find the source of registerAction(JComponent comp, Action action, String key)
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. |
static public void registerAction(JComponent comp, Action action, String key)
//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); } } }