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

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

问题描述

在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从其父级布局计算中排除,您还必须通过调用

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天全站免登陆