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:

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
source share