我想做的事情:
我有一个 JavaFX ScrollPane
,我需要确定 ScrollPane
中可见的区域。我知道 ScrollPane.getViewPortBounds()
,它允许我获取可见区域的大小,但不能获取位置。
有什么办法可以做到这一点吗?
<小时/>上下文:
我正在显示一个非常大的图像,一次只需要显示一部分。整个 ScrollPane
用于滚动图像,但要确定需要加载图像的哪些部分,我需要知道 ScrollPane
中显示的可见区域。
最佳答案
ScrollPane 还提供可见区域。此代码似乎有效:
Bounds bounds = scrollPane.getViewportBounds();
int lowestXPixelShown = -1 * (int)bounds.getMinX() + 1;
int highestXPixelShown = -1 * (int)bounds.getMinX() + (int)bounds.getMaxX();
关于JavaFX:获取ScrollPane的可见区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26141859/