Class ComponentKeyEventBinders

java.lang.Object
java.awt.event.KeyAdapter
com.inductiveautomation.ignition.designer.mvvm.binders.swing.ComponentKeyEventBinders
All Implemented Interfaces:
KeyListener, EventListener

public class ComponentKeyEventBinders extends KeyAdapter
Attaches a key-press listener to a Swing component that fires a callback when any key from a specified set is pressed.

Use the static install methods to attach the listener.

// Fire a simple action on Delete or Backspace:
ComponentKeyEventBinders.install(
    tree,
    Set.of(KeyEvent.VK_DELETE, KeyEvent.VK_BACK_SPACE),
    this::doDelete);

// Inspect which key was pressed:
ComponentKeyEventBinders.install(
    tree,
    Set.of(KeyEvent.VK_DELETE, KeyEvent.VK_BACK_SPACE),
    e -> handleKey(e.getKeyCode()));
  • Method Details

    • install

      public static void install(JComponent component, Set<Integer> keyCodes, Runnable onKey)
      Attaches a key listener that calls onKey when any key in keyCodes is pressed. Use this overload when you don't need to know which specific key was pressed.
      Parameters:
      component - the component to listen on
      keyCodes - the set of KeyEvent VK_* codes that trigger the callback
      onKey - called when a matching key is pressed
    • install

      public static void install(JComponent component, Set<Integer> keyCodes, Consumer<KeyEvent> onKey)
      Attaches a key listener that calls onKey with the triggering KeyEvent when any key in keyCodes is pressed. Use this overload when you need details about the key event, such as modifier keys.
      Parameters:
      component - the component to listen on
      keyCodes - the set of KeyEvent VK_* codes that trigger the callback
      onKey - called with the matching KeyEvent
    • keyPressed

      public void keyPressed(KeyEvent e)
      Specified by:
      keyPressed in interface KeyListener
      Overrides:
      keyPressed in class KeyAdapter