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());
If l want to hide and unhide a node,
I resize the node to 0 if l want to hide it. That way, the node will not occupy space since is not visible to the user, so when l want it to be visible, l adjust the size again for it to be visible.