JavaFX How do you convert coordinates (relative to the screen) to coordinates (relative to a pane)?

910 views Asked by At

I'm going the coordinates of my cursor from Java.AWT.MouseInfo and I need to convert it to the coordinate relative to a ScrollPane's viewport. I'm trying to have the scrollpane's scrollbar positions center on where the mouse was when zooming in/out.

viewScroll is a ScrollPane. zoomGroup is a Group containing an imageView that is scaled (zooming). When scaled the method repositions the scrollbars where it was before the scale. I want to reposition the scrollbars where the mouse was at the time of zooming.

protected void zoom(double scaleValue) {
    p = MouseInfo.getPointerInfo().getLocation();
    double Y = p.getX();
    double X = p.getY();

    double scrollH = viewScroll.getHvalue();
    double scrollV = viewScroll.getVvalue();

    zoomGroup.setScaleX(scaleValue);
    zoomGroup.setScaleY(scaleValue);

    viewScroll.setHvalue(Y);
    viewScroll.setVvalue(X);
}
0

There are 0 answers