Issue
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
.
Solution
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();
Answered By - John Cashew
Answer Checked By - Marilyn (JavaFixing Volunteer)