javafx : Scroll Pane bounds and its visible content bounds are not matching even when the scroll Vvalue = 0

519 Views Asked by At

I am printing the bounds of the scroll pane and its visible contents by using the following code:

    Bounds scrollBounds = scrollPane.localToScene(scrollPane.getBoundsInParent());
    System.out.println("ScrollPane Bounds: " + scrollBounds);

        if (scrollPane.getContent() instanceof Parent) 
        {
            Node n = (Node)scrollPane.getContent();
            Bounds contentBounds = n.localToScene(n.getBoundsInParent());
            System.out.println("Content Bounds: " + contentBounds);
        }

It gives the followint output :

ScrollPane Bounds: BoundingBox [minX:1.0, minY:30.0, minZ:0.0, width:862.0, height:505.0, depth:0.0, maxX:863.0, maxY:535.0, maxZ:0.0]
Content Bounds: BoundingBox [minX:2.0, minY:6.0, minZ:0.0, width:989.0, height:1296.0, depth:0.0, maxX:991.0, maxY:1302.0, maxZ:0.0]

If you observe the minY of the scroll pane and its contents, the start of the scrollPane content is 24 units ahead of the start of the scroll pane itself.(Though the scroll pane's Vvalue = 0, meaning scroll bar is at the top).

Also the minY of the Content is varying with the size of the window.(when window size is minimum it is 0 and when maximized it is around 20)

How is it possible? or Am I getting the bounds in a wrong way?

0

There are 0 best solutions below