Skip to main content

Is there a way to get x, y Position of a Node Object on Screen

5 replies [Last post]
riepi
Offline
Joined: 2008-03-27

Hi, is there a way to get x, y Position of a Node Object on Screen. I have got a Window which u can drag of course. Click on a Node will open a new Window with x and y from the clicked Node. So far i handle this Problem about a mouseevent with e.getScreenX/Y(), but it is not close enough.
Greetings

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kram
Offline
Joined: 2007-10-23

Each Node object has a "currentX" and "currentY", which according to the API:

currentX:
Read-only attribute returning the current x coordinate of this node relative to its parent.

(same for Y)

riepi
Offline
Joined: 2008-03-27

The relative x and y is easy to get with Node.getX/Y(), but i need the position on screen...but i think my try with the mouseposition also works fine
Thx, anyway

kram
Offline
Joined: 2007-10-23

I was just thinking, the javafx.application.Window object has X and Y properties, (which I have not looked too much into), but IF they were the frames coords within the users window, you could use those properties, then workout the exact position of the Node by its relative position to is parents.

Message was edited by: kram

riepi
Offline
Joined: 2008-03-27

Yes, of course this works. But it's complex when your node is in a deep node structure

kram
Offline
Joined: 2007-10-23

well yes and no, not having done this is fx script I cant really comment, but I have certainly seen this type of this done in a JavaScript environment, and all it really takes is a nice recursive function that adds up x and y coords, ending when we hit the top most level.

I would be happy to give it a try (even if for my own interest:) ) and report back, but it may not be until tonight sometime...