Here you can find the source of mapKeyStrokeToAction(final JComponent comp, final String ks, final String name, final AbstractAction action)
Parameter | Description |
---|---|
comp | JComponent |
ks | KeyStroke |
name | name |
action | action |
public static void mapKeyStrokeToAction(final JComponent comp, final String ks, final String name, final AbstractAction action)
//package com.java2s; import javax.swing.AbstractAction; import javax.swing.JComponent; import javax.swing.KeyStroke; public class Main { /**/* w ww . j av a 2 s .com*/ * Adds to JComponent action and keystroke for it. * * @param comp JComponent * @param ks KeyStroke * @param name name * @param action action */ public static void mapKeyStrokeToAction(final JComponent comp, final String ks, final String name, final AbstractAction action) { comp.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(ks), name); comp.getActionMap().put(name, action); } }