JavaFX-如何使VBox子代与VBox父代一起成长 [英] JavaFX - How to make VBox children grow with VBox parent

查看:220
本文介绍了JavaFX-如何使VBox子代与VBox父代一起成长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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);

我有一个扩展VBox的类,并且有三个也是VBox es的孩子.我写了一个方法,可以调整类的大小并使它变大/变小.当我将其放大时,其中的VBox不会随父级缩放.我不确定它是否在水平缩放,但不是垂直缩放.我尝试在线搜索解决方案,但找不到任何解决方案.感谢您的任何帮助,谢谢

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

推荐答案

您必须为VBoxes设置垂直增长约束:

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

VBox.setVgrow(box1, Priority.ALWAYS);

这篇关于JavaFX-如何使VBox子代与VBox父代一起成长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆