JVM | Platform | Status |
---|---|---|
OpenJDK (Temurin) Current | Linux | |
OpenJDK (Temurin) LTS | Linux | |
OpenJDK (Temurin) Current | Windows | |
OpenJDK (Temurin) LTS | Windows |
A JavaFX piano component.
- Simple piano display component.
- Display a configurable number of octaves.
- Capture key press/release events.
- Available in horizontal and vertical forms.
- Written in pure Java 21.
- OSGi-ready.
- JPMS-ready.
- ISC license.
Add a IvHorizontalPiano
or IvVerticalPiano
to your JavaFX layouts. Set a
IvKeyEventHandlerType
function to receive key events.
Keys are divided into naturals (the white keys) and accidentals (the black keys), mirroring the standard names from music theory.
The reason for avoiding white/black terminology is that the piano controls allow for complete control over key colors, and so keys may not actually be "black" or "white":
The piano controls publish events in response to user input. The following events are published:
IvKeyEnter
; the mouse cursor has moved over a specific key.IvKeyExit
; the mouse cursor is no longer over the specific key that it was previously over.IvKeyPressed
; the user has pressed the primary mouse button whilst over a key.IvKeyReleased
; the user has released the primary mouse button whilst over a key that was previously pressed.
The implementation attempts to provide sensible semantics with regard to
event delivery for individual keys. For example, for a given key k
, the
implementation won't publish a IvKeyReleased
event for k
before it
publishes a IvKeyPressed
event for k
. Due to the somewhat non-deterministic
nature of input event handling between the underlying platforms, the
implementation can't make many guarantees on the ordering between events
for different keys. For a given key k
, the implementation can largely
be trusted to publish events in the following orders:
IvKeyEnter k ⇒ IvKeyPressed k ⇒ IvKeyReleased k ⇒ IvKeyExit k
IvKeyEnter k ⇒ IvKeyExit k
A demo application is included.