JavaFX - How to make VBox children grow with VBox parent

寵の児 提交于 2019-12-02 03:27:09

问题


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

Here is a picture to visual the problem


回答1:


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

VBox.setVgrow(box1, Priority.ALWAYS);


来源:https://stackoverflow.com/questions/37062538/javafx-how-to-make-vbox-children-grow-with-vbox-parent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!