JavaFX - setVisible hides the element but doesn't rearrange adjacent nodes

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


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.


Try to use setVisible and managedProperty together. Here is an example:

myHBox.setVisible(false);
myHBox.managedProperty().bind(myHBox.visibleProperty());

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