0

When I want to get the height of a Borderpane in an Anchorpane it always returns 0.0

I tried:
a field : private double height;

a method:

public void setHeight() {
   height = borderPane.localToScene(borderPane.getBoundsInLocal()).getHeight();
}

and a listener in the constructor:

borderPane.heightProperty().addListener(ob -> setHeight());

I need it for the method:

public double getMiddenY(){
    return y + height/2;
}

If I debug, the field height changes correctly but at the end it's always 0.0

How can I fix this problem?

Jaymin Panchal
  • 2,797
  • 2
  • 27
  • 31
  • Um, can't you just use the `ob` in the listener to directly set `height`, instead of making a separate method? Just a thought – Salem Apr 02 '17 at 16:16
  • @1blustone well, that doesn't make a difference ( I tested and it doesn't work) – RikkiTheTramp Apr 02 '17 at 19:31
  • I'm almost sure this is a duplicate of this question: http://stackoverflow.com/questions/26152642/get-the-height-of-a-node-in-javafx-generate-a-layout-pass – fabian Apr 02 '17 at 19:40
  • I don't understand "the field `height` changes correctly but at the end it's always 0.0". What do you mean by "at the end" here? Are you saying that `height` changes correctly, but then somehow becomes zero again later? – James_D Apr 03 '17 at 17:46
  • @fabian thank you, found a solution. Didn't found that question, so thank you to show me – RikkiTheTramp Apr 05 '17 at 10:13
  • @James_D yes, indeed – RikkiTheTramp Apr 05 '17 at 10:13

0 Answers0