Вам нужен фон, а не просто такой цвет как
public class Main extends Application {
@Override
public void start(Stage stage) {
stage.setTitle(" ");
RadioButton rbRed = new RadioButton("Red");
RadioButton rbGreen = new RadioButton("Green");
ToggleGroup group = new ToggleGroup();
rbRed.setToggleGroup(group);
rbGreen.setToggleGroup(group);
HBox hbox = new HBox(rbRed, rbGreen);
hbox.setAlignment(Pos.CENTER);
rbRed.setOnAction(e -> {
if (rbRed.isSelected()) {
hbox.setBackground(buildBackground(Color.RED));
}
});
rbGreen.setOnAction(e -> {
if (rbGreen.isSelected()) {
hbox.setBackground(buildBackground(Color.GREEN));
}
});
Scene scene = new Scene(hbox, 400, 100);
stage.setScene(scene);
stage.show();
}
private Background buildBackground(Color color){
return new Background(new BackgroundFill(color,new CornerRadii(0),new Insets(0)));
}
public static void main(String[] args) { launch(args); }
}