Working in Java FX 2.2. The Scene has a horizontal width that is fixed but is unknown at compile time. I want to place 2 or more buttons in a horizontal row that completel
A bit cleaner solution with property binding:
HBox buttonLayout = new HBox();
buttonLayout.getChildren().add(button1);
buttonLayout.getChildren().add(button2);
int btnCount = buttonLayout.getChildren().size();
button1.prefWidthProperty().bind(buttonLayout.widthProperty().divide(btnCount));
button2.prefWidthProperty().bind(buttonLayout.widthProperty().divide(btnCount));