Java Utililty Methods Swing Key Event

List of utility methods to do Swing Key Event

Description

The list of methods to do Swing Key Event are organized into topic(s).

Method

voidretargetKeyEvent(KeyEvent e, Component target)
retarget Key Event
if ((target == null) || (target == e.getSource())) {
    return;
target.dispatchEvent(e);
voidsetKeystroke(JMenuItem m, int key)
set Keystroke
if (key > 0) {
    if (key != KeyEvent.VK_DELETE)
        m.setAccelerator(KeyStroke.getKeyStroke(key, Event.CTRL_MASK, false));
    else
        m.setAccelerator(KeyStroke.getKeyStroke(key, 0, false));
voidsimulateKeyPressed(Component component, int key)
Simulate a key press/release event on the component.
component.dispatchEvent(new KeyEvent(component, KeyEvent.KEY_PRESSED, 0, 1, key, KeyEvent.CHAR_UNDEFINED));
component.dispatchEvent(new KeyEvent(component, KeyEvent.KEY_RELEASED, 0, 2, key, KeyEvent.CHAR_UNDEFINED));