ricefieldboy
ricefieldboy

Reputation: 377

JavaFX - How to make VBox children grow with VBox parent

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

Upvotes: 6

Views: 8325

Answers (1)

jns
jns

Reputation: 6952

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

VBox.setVgrow(box1, Priority.ALWAYS);

Upvotes: 8

Related Questions