[Discussion] Add SwitchButton control to JavaFX

Andy Goryachev andy.goryachev at oracle.com
Tue Feb 17 22:10:50 UTC 2026


To me, it feels like this component belongs in a library (ControlsFX?), though I would imagine teams who work with mobile platforms might be more open to this possibility, as this type of control is frequently used in touch-based UIs.

The problem with a switch button in a desktop environment is that it is less accessible because it uses color to convey meaning.  Even on mobile platforms (at least, iOS) there is a system-wide accessibility setting to add a text decoration to it, something the JavaFX must be aware of.  A checkbox, on the other hand, is unambiguous.

I don't know whether the standard CheckBox control can be styled to look like a switch button.  We don't have a good handle on extending the behaviors, and even though the Skin is a public API, extending skins is not an easy task.

Other than that, good job designing a good looking control!  I might suggest making the sliding part flat (not the toggle itself, but the depressed area that changes color).  Since it is depressed in a real world switch, you might want to add a shadow instead of a convex gradient.  There is still a lot of variation in the design, even various platforms do not agree on how to render these things (using your example https://github.com/leewyatt/SwitchButtonShowcase )

-andy



From: openjfx-discuss <openjfx-discuss-retn at openjdk.org> on behalf of wyatt lee <leewyatt7788 at gmail.com>
Date: Friday, February 13, 2026 at 09:42
To: openjfx-discuss at openjdk.org <openjfx-discuss at openjdk.org>
Subject: [Discussion] Add SwitchButton control to JavaFX

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/20260217/5c6a48d7/attachment-0001.htm>


More information about the openjfx-discuss mailing list