JavaFX - setVisible 隐藏元素但不重新排列相邻节点 [英] JavaFX - setVisible hides the element but doesn't rearrange adjacent nodes

查看:23
本文介绍了JavaFX - setVisible 隐藏元素但不重新排列相邻节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 JavaFX 中,如果我有一个包含 2 个 VBox 元素的场景,并且每个 VBox 中都有多个 Label.
如果我将顶部VBox设置为invisible,为什么底部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 隐藏元素但不重新排列相邻节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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