Getting position in Scene of a Node with localToScene(x,y) returns wrong value

邮差的信 提交于 2020-01-06 04:01:05

问题


I want to bind the position of a pane that pops up to the position of the Button calling it, and I tried doing so by callling button.localToScene(button.getLayoutX(),button.getLayoutY(). However the returned Point2D variable has the wrong X coordinate in it. I measured it in Gimp and its supposed to be at 320 but it returns me 586.

Same story with localToScreen() btw, I dont even have 586 pixels of screen estate until the button already shows up, so its impossible for it to be at that coordinate.


回答1:


You may want to get the button's node position relevant to the element that contains the button such as a pane or the scene, if you provide code it would help. But something like this where you get the location of the pane that contains your button, then get ur button position and work out the difference. But i suggest trying this:

Bounds boundsInScene = button.localToScene(button.getBoundsInLocal());

Or this relative to the screen:

Bounds boundsInScreen = button.localToScreen(button.getBoundsInLocal());

Then use the methods : getMinX(), getMinY(), getMaxX(), getMaxY(), getWidth() or getHeight() to get the values of your actual button.

Hope this helps.



来源:https://stackoverflow.com/questions/38612350/getting-position-in-scene-of-a-node-with-localtoscenex-y-returns-wrong-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!