JavaFX imageview real coordinates translateX and translateY

僤鯓⒐⒋嵵緔 提交于 2019-12-01 14:53:54

I don't know what "real coordinate" means: which coordinate system are you wanting (screen, scene, parent, node...)?

The value you are displaying is the translateY property; it's the amount by which the node is translated vertically. So -24.8 means it's moved 24.8 units up from its original position.

You can look at the boundsInParent property, which tells you the bounds of the node in the parent's coordinate system, including any transforms (such as the translation). The boundsInLocal property is the bounds of the node in its own coordinate system, and doesn't include any transforms.

If you want to get the bounds of the node in scene or screen coordinates, you can use one of the many localToScene(...) or localToScreen(...) methods to convert.

Update: For example, to track the bounds of the image in scene coordinates, you can do something like:

ChangeListener<Number> listener = new ChangeListener<Number>() {
    @Override
    public void changed(ObservableValue<? extends Number> ov, Number oldValue, Number newValue) {
        Bounds boundsInScene = iv2.localToScene(iv2.getBoundsInLocal());
        double xInScene = boundsInScene.getMinX();
        double yInScene = boundsInScene.getMinY();
        // do something with values...
    }
});
iv2.translateXProperty().addListener(listener);
iv2.translateYProperty().addListener(listener);

Read the Javadocs for Node for more details.

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