Stack Exchange
Javafx : test with a layout manager?
I'm learning javafx and I made few try with the vbox layout manager. The code seems to be ok but I wanna check if I really understood how it works.
Here is the code :
public class TestShape2 extends Application {

  public static void main(String[] args) {
      launch(args);
  }

  @Override
  public void start(Stage primaryStage) throws Exception {
      Group root = new Group();
      Label topLabel = new Label("Top...");
      Label topLabel2 = new Label("Top 2...");
      Rectangle rect = new Rectangle();

      rect.setFill(Color.AQUA);
      Label bottomLabel = new Label("Bottom...");

      VBox vBox = new VBox();
      rect.widthProperty().bind(vBox.widthProperty());
      rect.heightProperty().bind(vBox.heightProperty());

      vBox.getChildren().addAll(topLabel, topLabel2, rect, bottomLabel);
      /*
       * Code 1
       */
      root.getChildren().add(vBox);
      Scene scene = new Scene(root, 300, 300, Color.BLANCHEDALMOND);

      /*
       * Code 2
       */
      // Scene scene = new Scene (vBox, 300, 300, Color.BLANCHEDALMOND);

      primaryStage.setScene(scene);
      primaryStage.show();

  }

}

In the "code 1" : does the width and height of the vBox are those of the elements contained in the root ass the root group is the parent of the vbox ? And so, the vBox don't fill the whole space ?
In the "code 2" : as I don't use some root group, the vbox dimensions will be the ones of the scene as the scene is the parent of the vbox ? 
Does my understanding is correct ?
If that's correct, my question is : what would be the code to have a "top label", a "bottom label" and a rectangle that would fill all the free space ? In the code 2, I never see the bottom label" as it seems the rectangle height is the height of the scene so, I suppose the bottom label is out of the scene. But how to solve that ?
Thank you all for your help in understanding javafx

This
rect.heightProperty().bind(vBox.heightProperty());

is a thing you should not do. It resizes the Rectangle according to the size of its parent. However there the height of the parent depends on the size of its children. This circular dependency leads to the VBox's behavior no longer being well defined...

In the "code 1" : does the width and height of the vBox are those of the elements contained in the root ass the root group is the parent of the vbox ?

The size of a Group's children is the prefered size. Combined with the issue described above you get a layout that does not fill the whole width/height available.

In the "code 2" : as I don't use some root group, the vbox dimensions will be the ones of the scene as the scene is the parent of the vbox ?

Mostly correct except for some imprecise formulation: The Scene is not the parent of any Node. The VBox is the root of the Scene and the Scene contains the VBox.

In the code 2, I never see the bottom label" as it seems the rectangle height is the height of the scene so, I suppose the bottom label is out of the scene.

That is correct.
Rectangle is not a resizable so it doesn't work well with a VBox parent to achieve the desired behavior. You can use ´Region´ instead however, which is resizable. Filling can be done using the Region's background and stroke could replaced by a border, if needed.
Setting vgrow to Priority.ALWAYS tells the VBox to always resize the Region instead of other children and setting fillWidth to true tells the VBox to change the children's size to it's own width:
@Override
public void start(Stage primaryStage) throws Exception {
    Label topLabel = new Label("Top...");
    Label topLabel2 = new Label("Top 2...");

    Region rect = new Region();
    rect.setBackground(new Background(new BackgroundFill(Color.AQUA, CornerRadii.EMPTY, Insets.EMPTY)));

    Label bottomLabel = new Label("Bottom...");

    VBox vBox = new VBox();
    vBox.setFillWidth(true);

    VBox.setVgrow(rect, Priority.ALWAYS);

    vBox.getChildren().addAll(topLabel, topLabel2, rect, bottomLabel);

    Scene scene = new Scene (vBox, 300, 300, Color.BLANCHEDALMOND);
    primaryStage.setScene(scene);
    primaryStage.show();
}

