The Bindings class has a helper function for custom bindings:
// chapter3.other.CreateBinding.java
Bindings.createObjectBinding(
()-> btn.isPressed() ? Color.RED : Color.GREEN, // computeValue logic
btn.pressedProperty() // list of observed values
);
And, as a small reminder, let's rewrite this binding once again using the Boolean binding operations we reviewed in the preceding code:
scene.fillProperty().bind(
Bindings.when(btn.pressedProperty())
.then(Color.RED)
.otherwise(Color.GREEN));