4 Replies Latest reply: Jan 13, 2013 8:50 PM by bouye RSS

    Behaviour of Node#visible

    Knut Arne Vedaa
      I'm not quite sure about the behaviour of Node#visible(). According to the API doc it "Specifies whether this Node and any subnodes should be rendered as part of the scene graph."

      The result I get, at least when applied to Button and TextField inside a ToolBar, is that is when they are set to not visible, there is empty space where they should have been.

      The behaviour I would like is that they should not take up space at all. Is there any way to achieve that without removing them from the scene graph?
        • 1. Re: Behaviour of Node#visible
          Hi. Use setVisible and setManaged together
          • 2. Re: Behaviour of Node#visible
            You can bind them for good measure if you like.
            • 3. Re: Behaviour of Node#visible
              I had the exact same question you have.
              Setting a Node to invisble does not seem to remove it from the layout. Removing it from the scene does.
              I have had no problems with the second approach so far. Everything seems to work fine if you re-add them later.

              I remove Nodes from a GridPane and re-add them later all the time, in case I need to change the tab-order (which, afaik, depends on the order in which the nodes are added).

              So I would suggest you just try removing them, and see what happens.
              Also note that the Stage class has a sizeToScene() method (inherited from Window) that you can use to resize the window to its new preferred size, if you've added some Nodes after the Stage was already sized and shown on screen.

              Although the setManaged(false) approach mentioned by shakir is probably more correct if you want to simply hide a node.

              Edited by: svanimpe on Jan 12, 2013 4:52 AM
              • 4. Re: Behaviour of Node#visible
                svanimpe wrote:
                Although the setManaged(false) approach mentioned by shakir is probably more correct if you want to simply hide a node.
                It works Ok but not everywhere, ie: not in layouts that may have spacing values in between elements such as HBox or VBox.
                True, the unmanaged & invisible control takes not space BUT it's still there so the layout will still insert additional space around the control.

                Imagine you have:
                (control A) spacing (control B) spacing (control C)

                And then you make (control B) unmanaged & invisible, you'll end up with:
                (control A) spacing spacing (control C)

                If you want:
                (control A) spacing (control C)

                then you need to remove (control B) from the scene.