- Enclosing class:
KeyEvents
public static interface KeyEvents.Builder
A Builder for adding a key event to a component, with a default onKeyRelease trigger
and condition
JComponent.WHEN_FOCUSED.
A key stroke already bound to a different action on a component, under the same condition, is rejected
when enabled, the binding must be disabled first, or replaced via replace(JComponent...).
Bindings installed by the look and feel can be overridden.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptioncondition(int condition) Sets the key event condition,JComponent.WHEN_FOCUSEDby default.disable(Collection<JComponent> components) Disables this key event on the given componentsdisable(JComponent... components) Disables this key event on the given componentsenable(Collection<JComponent> components) Builds the key event and enables it on the given componentsenable(JComponent... components) Builds the key event and enables it on the given componentskeyChar(char keyChar) keyCode(int keyCode) modifiers(int modifiers) onKeyRelease(boolean onKeyRelease) Default false.replace(Collection<JComponent> components) Builds the key event and enables it on the given components, replacing any existing binding of the key stroke under the same condition.replace(JComponent... components) Builds the key event and enables it on the given components, replacing any existing binding of the key stroke under the same condition.
-
Method Details
-
keyCode
- Parameters:
keyCode- the key code- Returns:
- this builder instance
-
keyChar
- Parameters:
keyChar- the key char- Returns:
- this builder instance
-
modifiers
- Parameters:
modifiers- the modifiers- Returns:
- this builder instance
-
onKeyRelease
Default false.- Parameters:
onKeyRelease- true if on key release- Returns:
- this builder instance
-
keyStroke
- Parameters:
keyStroke- the keyStroke- Returns:
- this builder instance
-
condition
Sets the key event condition,JComponent.WHEN_FOCUSEDby default.- Parameters:
condition- the condition- Returns:
- this builder instance
-
action
- Parameters:
action- the action, if null then the action binding is removed- Returns:
- this builder instance
-
enable
Builds the key event and enables it on the given components- Parameters:
components- the components- Returns:
- this builder instance
- Throws:
IllegalStateException- in case no action has been set or in case the key stroke is already bound to a different action on a component, under the same condition
-
enable
Builds the key event and enables it on the given components- Parameters:
components- the components- Returns:
- this builder instance
- Throws:
IllegalStateException- in case no action has been set or in case the key stroke is already bound to a different action on a component, under the same condition
-
replace
Builds the key event and enables it on the given components, replacing any existing binding of the key stroke under the same condition.- Parameters:
components- the components- Returns:
- this builder instance
- Throws:
IllegalStateException- in case no action has been set
-
replace
Builds the key event and enables it on the given components, replacing any existing binding of the key stroke under the same condition.- Parameters:
components- the components- Returns:
- this builder instance
- Throws:
IllegalStateException- in case no action has been set
-
disable
Disables this key event on the given components- Parameters:
components- the components- Returns:
- this builder instance
- Throws:
IllegalStateException- in case no action has been set
-
disable
Disables this key event on the given components- Parameters:
components- the components- Returns:
- this builder instance
- Throws:
IllegalStateException- in case no action has been set
-