Class KeyBinding.Builder
- Enclosing class:
KeyBinding
public static class KeyBinding.Builder extends Object
KeyBinding objects. By default, its build method creates a key KEY_PRESSED binding. This can be changed by calling either keyReleased() or keyTyped().
The builder pattern can be used when convenience methods such as KeyBinding.control(KeyCode) or KeyBinding.shiftShortcut(KeyCode) are not sufficient.
Example:
KeyBinding.builder(KeyCode.TAB).control().option().shift().build()
- Since:
- 24
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
KeyBinding.Builder |
alt() |
Sets the alt key down condition (the option key on macOS). |
KeyBinding |
build() |
Creates a new KeyBinding instance from the current settings. |
KeyBinding.Builder |
command() |
Sets the command key down condition on macOS. |
KeyBinding.Builder |
control() |
Sets the control key down condition. |
KeyBinding.Builder |
keyReleased() |
Sets the KEY_RELEASED condition, clearing KEY_PRESSED and KEY_TYPED. |
KeyBinding.Builder |
keyTyped() |
Sets the KEY_TYPED condition, clearing KEY_PRESSED and KEY_RELEASED. |
KeyBinding.Builder |
meta() |
Sets the meta key down condition. |
KeyBinding.Builder |
option() |
Sets the option key down condition on macOS. |
KeyBinding.Builder |
shift() |
Sets the shift key down condition. |
KeyBinding.Builder |
shortcut() |
Sets the shortcut key down condition. |
Method Details
keyReleased
public KeyBinding.Builder keyReleased()
- Returns:
- the Builder instance
keyTyped
public KeyBinding.Builder keyTyped()
- Returns:
- the Builder instance
alt
public KeyBinding.Builder alt()
alt key down condition (the option key on macOS).- Returns:
- this Builder
command
public KeyBinding.Builder command()
command key down condition on macOS. Setting this condition on non-macOS platforms will result in the build method returning null.
- Returns:
- this Builder
control
public KeyBinding.Builder control()
control key down condition.- Returns:
- this Builder
meta
public KeyBinding.Builder meta()
meta key down condition.- Returns:
- this Builder
option
public KeyBinding.Builder option()
option key down condition on macOS. Setting this condition on non-macOS platforms will result in the build method returning null.
- Returns:
- this Builder
shift
public KeyBinding.Builder shift()
shift key down condition.- Returns:
- this Builder
shortcut
public KeyBinding.Builder shortcut()
shortcut key down condition.- Returns:
- this Builder
build
public KeyBinding build()
KeyBinding instance from the current settings.- Returns:
- a new key binding instance.
© 2008, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from JavaFX API Documentation.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Java, JavaFX and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.