0

I have the following problem. I've got this VBox wrapped in an AnchorPane:

<AnchorPane>
   <children>
      <VBox fx:id="sidebar" prefHeight="400.0" prefWidth="150.0" AnchorPane.bottomAnchor="0.0" AnchorPane.topAnchor="0.0"/>
   </children>
</AnchorPane>

And I want to get the displayed height of this vbox (even after e.g. resizing the Anchorpane around it.)
So I tried the following:

double height = sidebar.getHeight();

but for some reason getHeight() just returns 0. So... how do I get the height of that vbox?

Mark
  • 69
  • 1
  • 1
  • 8

1 Answers1

0

There a several possible reasons, why getHeight() returns '0'.

  1. Your VBox doesn't contain any children.
  2. It's not in the SceneGraph yet.
jns
  • 6,017
  • 2
  • 23
  • 28
  • I've just realized that you set the anchor constraints for the vbox. So `sidebar.getHeight()` should return a value equal to the height of the `AnchorPane`. Are you sure you're using the correct reference for sidebar? – jns Apr 30 '16 at 22:14
  • Okay, I've added children to the VBox now. I previously had the getHeight() in the initialize-method of my Controller, there it returned 0. Now I wrote a method that returns the height on button press, there it worked. – Mark Apr 30 '16 at 22:18
  • Or 3. The `VBox` simply has not yet been layouted... – fabian May 01 '16 at 08:52