JavaFX - delimited toggle button

Java FX Scen Builder contains a rather special kind of toggle button. Several buttons are visually combined and separated by a small vertical line:

enter image description here

I wonder how this is done. Somebody knows?

+4
source share
2 answers

As a simplified alternative to custom CSS, the Controls FX project provides a Segmented Button control that allows you to visually group buttons just like the OP asked.

This is a BSD license, so I assume that it is safe to use in most cases. And the library has many other useful and well-designed controls.

The segmented button is as follows:

enter image description here

Very simple:

 ToggleButton tb1 = new Button("Red"); ToggleButton tb1 = new Button("Green"); ToggleButton tb1 = new Button("Blue"); SegmentedButton seg = new SegmentedButton(); seg.getButtons().addAll(tb1,tb2,tb3); hbox.getChildren().add(seg); 

Allows you to specify whether the choice should be mutually exclusive or not. For the second bwhaviour (without mutual exclusion) set the group of segmented buttons to null:

 seg.setToggleGroup(null); 

Source: http://controlsfx.bitbucket.org/org/controlsfx/control/SegmentedButton.html

0
source

All Articles