JavaFX - setVisible doesn't “hide” the element

2019-01-10 23:56发布

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 ?

The VBox is invisible but I would expect the other objects to move into its place.

I am using FXML to load my controls.

3条回答
劳资没心,怎么记你
2楼-- · 2019-01-11 00:38

Node.setVisible(boolean) just toggles the visibility state of a Node.

To exclude a Node from its parents layout calculations you additionally have to set its managed state, by calling Node.setManaged(false).

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

查看更多
戒情不戒烟
3楼-- · 2019-01-11 00:52

Since it's invisible, it wont move to the top. You have to remove it with something like:

// remove
vbox.getChildren().remove(...)

Once you've removed the element you want invisible then, the other element should move to the top.

查看更多
ら.Afraid
4楼-- · 2019-01-11 00:53

Instead of hiding the vbox you should remove it from the Children and if you want to show it again add the vbox again.

查看更多
登录 后发表回答