JavaFX why does ScrollPane require two group wrappings to re-compute its scollbars?

143 views Asked by At

In this example, an image of a map is set on a ScrollPane in the FXML file.

http://hg.openjdk.java.net/openjfx/8u-dev/rt/rev/36a59c629605

The image is resizable by some other method that changes the scale of the Group - zoomGroup - containing the image.

+    private void zoom(double scaleValue) {
+//    System.out.println("airportapp.Controller.zoom, scaleValue: " + scaleValue);
+        double scrollH = map_scrollpane.getHvalue();
+        double scrollV = map_scrollpane.getVvalue();
+        zoomGroup.setScaleX(scaleValue);
+        zoomGroup.setScaleY(scaleValue);
+        map_scrollpane.setHvalue(scrollH);
+        map_scrollpane.setVvalue(scrollV);
+    }

But in order to make sure the ScrollPane re-computes its scrollbars (so the scrollable area effectively changes to include the entire image at any scale) the Group that wraps the Image, zoomGroup, is then wrapped in another Group, contentGroup, which is set as the ScrollPane's content.

+        // Wrap scroll content in a Group so ScrollPane re-computes scroll bars
+        Group contentGroup = new Group();
+        zoomGroup = new Group();
+        contentGroup.getChildren().add(zoomGroup);
+        zoomGroup.getChildren().add(map_scrollpane.getContent());
+        map_scrollpane.setContent(contentGroup);

Can someone explain why this is necessary?

This is the video that accompanies the files: https://www.youtube.com/watch?v=ij0HwRAlCmo

0

There are 0 answers