[Discussion] Add SwitchButton control to JavaFX

wyatt lee leewyatt7788 at gmail.com
Fri Feb 13 17:42:30 UTC 2026


Hi all,

I'd like to discuss the possibility of adding a SwitchButton control to
JavaFX.

## Motivation

The switch control has become a standard UI element across all major
platforms:
- iOS/macOS: Toggle
- Android: MaterialSwitch
- Flutter: Switch, CupertinoSwitch
- Windows (WinUI): ToggleSwitch

Currently, JavaFX lacks a native Switch control.

## Why Not CheckBox or ToggleButton?

The visual form is fundamentally different:
- CheckBox: box + checkmark
- ToggleButton: button with pressed/released states
- SwitchButton: sliding track + circular thumb

Beyond appearance, SwitchButton is also semantically unique:
- Unlike CheckBox: no indeterminate state, takes effect immediately (not
form submission)
- Unlike ToggleButton: no ToggleGroup support, designed for independent
on/off settings

## Why Not ControlsFX's ToggleSwitch?

ControlsFX's ToggleSwitch has served the community well, but has
architectural issues:

1. **Control level**: Extends Labeled instead of ButtonBase (inconsistent
with CheckBox/RadioButton/ToggleButton)

2. **Skin level**: ToggleSwitchSkin extends SkinBase<ToggleSwitch> instead
of LabeledSkinBase, so it cannot reuse the label layout logic. It creates
an internal Label, which causes most Labeled properties (textFill, graphic,
contentDisplay) to not work as expected.

Fixing these would require rewriting 80%+ of the code and break existing
users. Given that Switch is a fundamental UI component, it makes sense to
include it in JavaFX core.

## Prototype

I've created a working implementation:
- Showcase: https://github.com/leewyatt/SwitchButtonShowcase
- Implementation: https://github.com/leewyatt/jfx/tree/add-switch-button-v2

Key design decisions:
- Extends ButtonBase (consistent with other toggle controls)
- Skin extends LabeledSkinBase (full Labeled property support)
- Styles for both Modena and Caspian themes

I'd appreciate any feedback on whether this would be a valuable addition to
JavaFX core.

Thanks,
Lee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/openjfx-discuss/attachments/20260214/c8734d92/attachment.htm>


More information about the openjfx-discuss mailing list