Class ComponentKeyEventBinders
java.lang.Object
java.awt.event.KeyAdapter
com.inductiveautomation.ignition.designer.mvvm.binders.swing.ComponentKeyEventBinders
- All Implemented Interfaces:
KeyListener, EventListener
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 Summary
Modifier and TypeMethodDescriptionstatic voidinstall(JComponent component, Set<Integer> keyCodes, Runnable onKey) Attaches a key listener that callsonKeywhen any key inkeyCodesis pressed.static voidAttaches a key listener that callsonKeywith the triggeringKeyEventwhen any key inkeyCodesis pressed.voidMethods inherited from class KeyAdapter
keyReleased, keyTyped
-
Method Details
-
install
Attaches a key listener that callsonKeywhen any key inkeyCodesis pressed. Use this overload when you don't need to know which specific key was pressed.- Parameters:
component- the component to listen onkeyCodes- the set ofKeyEventVK_* codes that trigger the callbackonKey- called when a matching key is pressed
-
install
Attaches a key listener that callsonKeywith the triggeringKeyEventwhen any key inkeyCodesis pressed. Use this overload when you need details about the key event, such as modifier keys. -
keyPressed
- Specified by:
keyPressedin interfaceKeyListener- Overrides:
keyPressedin classKeyAdapter
-