List of utility methods to do Swing KeyStroke
void | addShortcutToComponent(final JComponent component, final KeyStroke keystroke, final String actionCommand, final Action action) Adds the shortcut to component. addShortcutToComponent(component, keystroke, JComponent.WHEN_IN_FOCUSED_WINDOW, actionCommand, action); |
void | addShortcutToComponent(JComponent component, KeyStroke keystroke, String actionCommand, Action action) Adds the shortcut to component. addShortcutToComponent(component, keystroke, JComponent.WHEN_IN_FOCUSED_WINDOW, actionCommand, action); |
void | bindAction(JComponent aComponent, String aCommand, Action anAction, KeyStroke aKeyStroke) bind Action aComponent.getInputMap(JComponent.WHEN_FOCUSED).put(aKeyStroke, aCommand); aComponent.getActionMap().put(aCommand, anAction); |
void | bindKeyToAction(int keyCode, int modifiers, Action action, JComponent component, int condition) bind Key To Action KeyStroke keyStroke = KeyStroke.getKeyStroke(keyCode, modifiers); component.getInputMap(condition).put(keyStroke, action); |
void | bindKeyToAction(JComponent c, KeyStroke key, Action a) Convenience wrapper for #bindKeyToAction(JComponent,KeyStroke,Action,int) bindKeyToAction(c, key, a, JComponentn.WHEN_FOCUSED) . bindKeyToAction(c, key, a, JComponent.WHEN_FOCUSED); |
void | clearActionBinding(final JComponent component, final KeyStroke keyStroke, final int condition) Clears the action key registered under the given keystroke. InputMap map = component.getInputMap(condition);
while (map != null) {
map.remove(keyStroke);
map = map.getParent();
|
void | clearKeyStroke(JComponent component) clear Key Stroke InputMap inputMap = component.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); if (inputMap != null) { KeyStroke[] keyStrokes = inputMap.keys(); if (keyStrokes != null) { for (KeyStroke keyStroke : inputMap.keys()) { if (KEYID.equals(inputMap.get(keyStroke))) { inputMap.remove(keyStroke); break; ... |
void | closeOnKeyStroke(JRootPane rootPane, KeyStroke keyStroke) close On Key Stroke final String CLOSE_ACTION_NAME = "com.jakeapp.gui.swing.helpers.GuiUtilities.CloseFrameOnKeyStroke"; rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStroke, CLOSE_ACTION_NAME); rootPane.getActionMap().put(CLOSE_ACTION_NAME, CLOSE_ACTION); |
boolean | componentListensForKey(JComponent component, int keyCode) Returns whether a component listens for a key code, i.e. KeyStroke[] keyStrokes = component.getInputMap().allKeys(); if (keyStrokes == null) return false; for (int i = keyStrokes.length - 1; i >= 0; i--) { if (keyCode == keyStrokes[i].getKeyCode()) { return true; return false; |
void | configAction(Action action, String text, Icon icon, KeyStroke keyStroke) config Action action.putValue(NAME, text); action.putValue(SMALL_ICON, icon); action.putValue(ACCELERATOR_KEY, keyStroke); |