Make invisible controls in JavaFX

2

Is there any way to hide controls in javaFX so that they do not 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 keeps the space and forces me to restore the original sizes once the controls are visible again.

    
asked by Oundroni 15.04.2016 в 15:16
source

3 answers

-1

In the end I created two methods, one to hide a control and another to show it:

void esconderControl (Control control) {
        control.setVisible(false);
        control.setManaged(false);
}
void mostrarControl (Control control) {
        control.setVisible(true);
        control.setManaged(true);
}
esconderControl (miControl); // hace desaparecer miControl de pantalla
mostrarControl (miControl);  // hace aparecer miControl de pantalla

The setManaged(boolean) method stops managing the control, but it may continue to appear on the screen unexpectedly anywhere within its container, so it is also essential to use the SetVisible(bolean)

method     
answered by 21.04.2016 / 23:34
source
2

This option you tried, only works using the Android SDK:

control.setVisibility(View.GONE);

To hide a control in JavaFX, you can do it with:

 control.setVisible(false);

or if you do not want it to occupy space you have to remove it:

contenedor.getChildren().remove(control);

This is an example removing a button:

    
answered by 15.04.2016 в 17:37
1

You can try with the Node.setVisible(false) method that the node hides, or you can try with setManaged that goes a little further and stops managing the node, so they do not perform calculations with it.

You can check if it is managed (Managed) with the method isManaged()

    
answered by 15.04.2016 в 15:56