How to resize JavaFX ScrollPane content to fit current size

Solution 1:

Try

ScrollPane scrollPane = new ScrollPane();
scrollPane.setFitToHeight(true);
scrollPane.setFitToWidth(true);

without overriding the resize() method.

Solution 2:

Setting the fitToHeight or fitToWidth attribute through XML or CSS:

FXML:

<ScrollPane fx:id="myScrollPane" fitToHeight="true" fitToWidth="true" />

CSS:

.my-scroll-pane {
    -fx-fit-to-height: true;
    -fx-fit-to-width: true;
}