JavaFX - How to make VBox children grow with VBox parent
Asked Answered
I

1

6
VBox classBox = new VBox();
className = new Text("defaultClass");
classBox.setAlignment(Pos.CENTER);
classBox.getChildren().add(className);
classBox.getStyleClass().add(VM_BOXES);

variablesBox = new VBox();
variablesBox.getStyleClass().add(VM_BOXES);

methodsBox = new VBox();
methodsBox.getStyleClass().add(VM_BOXES);

this.getChildren().add(classBox);
this.getChildren().add(variablesBox);
this.getChildren().add(methodsBox);

this.getStyleClass().add(VM_BOXES);

Hi, I have a class that extends VBox and has three children that are also VBoxes. I have written a method where I can resize the class and make it bigger/smaller. When I make it larger, the VBoxes inside of it do not scale with the parent. I am not sure if it is scaling horizontally or not but It is not scaling vertically. I tried searching online for solutions but cannot find any. Any help is appreciated, thanks enter image description here

Here is a picture to visual the problem

Ibeam answered 6/5, 2016 at 0:50 Comment(0)
N
8

You have to set the vertical grow constraints for the VBoxes:

VBox.setVgrow(box1, Priority.ALWAYS);
Nestorius answered 6/5, 2016 at 1:7 Comment(3)
sorry, if youre still there, if you can tell me how to do the same thing for labels within those children VBoxes, I would would be really grateful.Ibeam
Set the vGrow to your Label as well, and set its maxHeight sufficiently highNestorius
@jns: talking about boxes inside boxes, IMHO the line you wrote can be misleading, I personally needed some trials and errors to get it right. - VBox is the name of the javaFX class (setVgrow is a static method) - box1 is the instance of the object you want to grow, so it should be replaced by label1 to answer your second questionEnamour

© 2022 - 2024 — McMap. All rights reserved.