Here you can find the source of installOperation(final RootPaneContainer frame, final int condition, final KeyStroke keyStroke, final String actionKey, Action action)
Parameter | Description |
---|---|
frame | The frame in which this keybind can be activated |
condition | When should this keybind be activated. Either JComponent#WHEN_FOCUSED , JComponent#WHEN_IN_FOCUSED_WINDOW , or JComponent#WHEN_ANCESTOR_OF_FOCUSED_COMPONENT . |
keyStroke | The keystroke used to activate the keybind |
actionKey | Identifier of the action |
action | The action to execute when the keybind is activated |
public static void installOperation(final RootPaneContainer frame, final int condition, final KeyStroke keyStroke, final String actionKey, Action action)
//package com.java2s; //License from project: Open Source License import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.JRootPane; import javax.swing.KeyStroke; import javax.swing.RootPaneContainer; public class Main { /**/*from w w w . j a va 2 s . c o m*/ * Installs a keybind in the specified frame for the specified action. * * @param frame * The frame in which this keybind can be activated * @param condition * When should this keybind be activated. * Either {@link JComponent#WHEN_FOCUSED}, {@link JComponent#WHEN_IN_FOCUSED_WINDOW}, or * {@link JComponent#WHEN_ANCESTOR_OF_FOCUSED_COMPONENT}. * @param keyStroke * The keystroke used to activate the keybind * @param actionKey * Identifier of the action * @param action * The action to execute when the keybind is activated */ public static void installOperation(final RootPaneContainer frame, final int condition, final KeyStroke keyStroke, final String actionKey, Action action) { JRootPane root = frame.getRootPane(); root.getInputMap(condition).put(keyStroke, actionKey); root.getActionMap().put(actionKey, action); } /** * {@linkplain #installOperation(RootPaneContainer, int, KeyStroke, String, Action)} */ public static Action installOperation(final RootPaneContainer frame, final int condition, final KeyStroke keyStroke, final String actionKey, final Runnable runnable) { Action result = new AbstractAction(actionKey) { public void actionPerformed(ActionEvent e) { runnable.run(); } }; installOperation(frame, condition, keyStroke, actionKey, result); return result; } }