4
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

fabian
  • 80,457
  • 12
  • 86
  • 114
ricefieldboy
  • 347
  • 1
  • 4
  • 15

1 Answers1

7

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

VBox.setVgrow(box1, Priority.ALWAYS);
jns
  • 6,017
  • 2
  • 23
  • 28
  • 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. – ricefieldboy May 06 '16 at 01:49
  • 1
    Set the vGrow to your Label as well, and set its maxHeight sufficiently high – jns May 06 '16 at 02:05
  • @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 question – massi May 27 '22 at 17:28