How to center the content of a javafx 8 scrollpane

后端 未结 4 1915
渐次进展
渐次进展 2021-01-04 20:21

I have a ScrollPane, which contains a GridPane, which contains an ImageView, which contains an Image. What I want is for the Image to be centered in the GridPane.

W

4条回答
  •  难免孤独
    2021-01-04 20:49

    While imageHolder.minWidthProperty().bind(Bindings.createDoubleBinding(() -> scroll.getViewportBounds().getWidth(), scroll.viewportBoundsProperty())); indeed does the trick, there seem to be some issues with it (e.g., sometimes showing erroneous scrollbars/flickering content, etc.).

    I since found that a simple scroll.setFitToWidth(true); (and/or scroll.setFitToHeight(true);) also keeps the content sized with the scroll pane, but without the aforementioned issues!

提交回复
热议问题