Java examples for Swing:Event
Adding an InputMap to a Component
import javax.swing.InputMap; import javax.swing.JComponent; import javax.swing.JTextField; import javax.swing.KeyStroke; public class Main { public static void main(String[] argv) { InputMap inputMap = new InputMap(); // Add a KeyStroke inputMap.put(KeyStroke.getKeyStroke("F2"), "actionName"); /*from ww w .j a v a2s . com*/ JTextField component = null; inputMap.setParent(component.getInputMap(JComponent.WHEN_FOCUSED)); component.setInputMap(JComponent.WHEN_FOCUSED, inputMap); } }