问题描述
在JavaFX中,如果我有一个包含2个VBox
元素的场景,并且每个VBox
中都有多个Label
.
如果将顶部VBox
设置为不可见,为什么底部VBox
不向上移动顶部VBox
所在的场景?
In JavaFX, if I have a scene with 2 VBox
elements and each VBox
has multiple Label
in it.
If I set the top VBox
to invisible, why does the bottom VBox
not move up the scene where the top VBox
was ?
VBox
是不可见的,但我希望其他对象移入其位置.
The VBox
is invisible but I would expect the other objects to move into its place.
我正在使用FXML加载控件.
I am using FXML to load my controls.
推荐答案
Node.setVisible(boolean)
只是切换Node
的可见性状态.
Node.setVisible(boolean)
just toggles the visibility state of a Node
.
要将Node
从其父级布局计算中排除,您还必须通过调用 Node.setManaged(false)
.
To exclude a Node
from its parents layout calculations you additionally have to set its managed state, by calling Node.setManaged(false)
.
如果您希望在可见性旁边自动更新托管状态,则可以使用@jewelsea指出的绑定:node.managedProperty().bind(node.visibleProperty());
If you want the managed state to be updated automatically alongside the visibility, you can use a binding as @jewelsea pointed out: node.managedProperty().bind(node.visibleProperty());
这篇关于JavaFX-setVisible隐藏元素,但不重新排列相邻节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!