Issue
I add some child nodes to a VBox, such as button and text. So, the VBox's width should be larger than 0, as it's showing on the scene.
But when I call the width value, it prints out 0.
Examples:
vbox.getWidth(); // prints 0
vbox.widthProperty(); // prints 0
How do I get the right width of vbox
?
Solution
Before the appearance of your scene
, the width and height of a VBox
or any Node
is not initialized. That's why you are getting 0 as a result. Try to get the size after the scene
is shown in its stage
. That way it will show the correct size.
Answered By - Harshita Sethi
Answer Checked By - Cary Denson (JavaFixing Admin)