I do not know why the JavaFX developers have not included this in the existing toolset, so I created this by myself based on the JavaFX BidirectionalBinding class: A BidirectionalBinding between a SelectionModel and an ObjectProperty.
Whenever the ObjectProperty changes, the selection is updated and when the selection changes the ObjectProperty is updated. I posted the code at Github.
Usage is typically by a static factory method, so here you go:
This method differs a little bit from the default JavaFX BidirectionalBindings by adding a third argument: The boolean argument is to decide where the initial value should be extracted from: Either from the ObjectProperty or the SelectionModel.
A very powerful and often underestimated feature of JavaFX is its CSS Color Derivation.
But let us start at the beginning by explaining two prerequisites:
The Default JavaFX 8 Theme (Modena) only defines a few colors statically in its stylesheet. The rest is derived by JavaFX’s color functions (ladder and derive - see the CSS Reference) or referenced as color variables.
If you start to apply a custom styles to a Node in the scenegraph, these styles will also be applied to all children of this Node (if applicable). So changing a color variable on a single node will change the corresponding colors, derived colors and referenced colors on all child nodes in the scenegraph, but not on any of its parent nodes.
If we combine both together we can create these three Buttons with ease (the first one is a regular one, just to show the default theme):