Here you can find the source of addComponentAction(final JComponent component, final Action action)
Parameter | Description |
---|---|
component | The compoenet to add the action to |
action | The action to add |
public static void addComponentAction(final JComponent component, final Action action)
//package com.java2s; /*// www . ja va2 s . c o m * Copyright (C) 2010-2012 Klaus Reimer <k@ailis.de> * See LICENSE.TXT for licensing information. */ import javax.swing.Action; import javax.swing.ActionMap; import javax.swing.InputMap; import javax.swing.JComponent; import javax.swing.KeyStroke; public class Main { /** * Adds a component action. * * @param component * The compoenet to add the action to * @param action * The action to add */ public static void addComponentAction(final JComponent component, final Action action) { final InputMap imap = component .getInputMap(component.isFocusable() ? JComponent.WHEN_FOCUSED : JComponent.WHEN_IN_FOCUSED_WINDOW); final ActionMap amap = component.getActionMap(); final KeyStroke ks = (KeyStroke) action.getValue(Action.ACCELERATOR_KEY); imap.put(ks, action.getValue(Action.NAME)); amap.put(action.getValue(Action.NAME), action); } }