Search code examples
javajavafxcomponentstogglebutton

JavaFX Get Koordinates from Toggle Button


I have a ToggleButton in JavaFX. I want to know on which Coordinate this ToggleButton is. Is there a Function that delivers this values like:

getCoordinates or something like that?

Thank you for your help :)


Solution

  • Depending on whether you want to know the position a) on screen, b) in the scene, c) in the parent node, use Node's methods localToScreen, localToScene or localToParent, respectively.

    Example

    To get the top left corner of your toggle button in the scene, do

    Point2D pos = toggleButton.localToScene(0.0, 0.0);