Is this the correct way to make VBox fill its parent:
final Group root = new Group();
final Scene scene = new Scene(root, 1000, 800, Color.BLACK);
final VBox c = new VBox();
c.setAlignment(Pos.TOP_CENTER);
c.setSpacing(10);
c.setFillWidth(true);
c.getChildren().add(...);
c.getChildren().add(...);
c.getChildren().add(...);
c.prefWidthProperty().bind(scene.widthProperty());
c.prefHeightProperty().bind(scene.heightProperty());
root.getChildren().add(c);
stage.setTitle("blah"); //$NON-NLS-1$
stage.setScene(scene);
stage.show();
You can achieve the same functionality without using bind, using only BorderPane instead of Group
final BorderPane root = new BorderPane();
// construct your VBox
root.setCenter(vbox);
You are making a common mistake.
It's not necessary to create a Group as the root, just directly use VBox as the root and add it to the scene.
final Scene scene = new Scene(c, 1000, 800, Color.BLACK);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With