Get real position of a node in JavaFX

后端 未结 3 1174
感情败类
感情败类 2020-12-06 17:06

What is the best way to get the absolute position of a node in JavaFX?

Imagine we have a node in a Pane (Hbox, Stackpane, or any other pane) and that may have a pare

3条回答
  •  無奈伤痛
    2020-12-06 18:03

    if you want to translate local coordinates to scenne coords you can use localToScene method .

     Point2D point2D = node.localToScene(0,0);
    

    for example if you want to know the center of a pane but in scene coordinates

    Point2D point2D = pane.localToScene(pane.getWidth()/2,pane.getHeight()/2);
    

提交回复
热议问题