midrare
midrare

Reputation: 2774

JavaFX: Get visible area of ScrollPane

What I want to do:
I've got a JavaFX ScrollPane and I need to determine the area visible in the ScrollPane. I know about ScrollPane.getViewPortBounds(), which allows me to get the size of the visible area, but not the position.

Is there any way I can do this?


In context:
I'm displaying a very large image, which needs to be displayed in only portions at a time. The entire ScrollPane is used to scroll the image, but to determine which parts of the image I need to load, I need to know the visible area displayed in the ScrollPane.

Upvotes: 5

Views: 3737

Answers (1)

John Cashew
John Cashew

Reputation: 1084

ScrollPane also provides the visible area. This code seems to work:

    Bounds bounds = scrollPane.getViewportBounds();
    int lowestXPixelShown = -1 * (int)bounds.getMinX() + 1;
    int highestXPixelShown = -1 * (int)bounds.getMinX() + (int)bounds.getMaxX();

Upvotes: 1

Related Questions