Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide some elements without occupying space in javaFx

Tags:

java

javafx-8

Can anyone tell me is there any display:none property in JavaFX like in Css?

Actually I want to hide some labels and don't want them to occupy space when hidden.

How can I achieve this in JavaFX?

TIA

like image 845
K.M.S Avatar asked Mar 01 '18 13:03

K.M.S


1 Answers

Nodes are considered for layout purposes by parents as long as their managed property is true. For this reason you need to set both the visible and the managed property:

node.setVisible(false);
node.setManaged(false);

This is an alternative to simply removing the node from it's parent that allows you to make the node reappear again. If you don't want do anything with the node after hiding it, you should simply remove it from the scene instead:

parentLayout.getChildren().remove(node);
like image 129
fabian Avatar answered Sep 22 '22 13:09

fabian