How to get VBox to fill in its parent size

Is it correct to have VBox populate the parent element:

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(); 
+8
javafx-2
source share
2 answers

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); 
+21
source share

You make a common mistake.

No need to create a group as a root, just use VBox as a root and add it to the scene.

 final Scene scene = new Scene(c, 1000, 800, Color.BLACK); 
+1
source share

All Articles