Is there a way to hide controls in javaFX so that they don't take up space? I have seen that in android it is possible: control.setVisibility(View.GONE);
What comes to mind is this:
control.setVisible(false);
control.setMinSize(0,0);
control.setMaxSize(0,0);
control.setPrefSize(0,0);
but it preserves my space and forces me to restore the original sizes once the controls are visible again.
This option you tried only works using the Android SDK :
To hide a control in JavaFX, you can do it with:
or if you don't want it to take up space you have to remove it:
This is an example removing a button:
You can try the method
Node.setVisible(false)
that hides the node, or you can try setManaged which goes a bit further and stops managing the node, so no calculations are done with it.You can check if it is managed (Managed) with the method
isManaged()
In the end I have created two methods, one to hide a control and another to show it:
The method
setManaged(boolean)
stops handling the control, but it can still pop up on the screen unexpectedly anywhere inside its container so it's imperative to also use the methodSetVisible(bolean)