I have a FlowPane inside a ScrollPane. Inside the flow pane I put four Rectangle shapes. When I resized (reducing) the window the scroll pane didn't showed up the scrollbar as shown below:
But it showed up at some point when I reduce the size more.
Below is my code:
public class FlowPaneInsideScrollPane extends Application{
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
ScrollPane scrollPane = new ScrollPane();
scrollPane.setFitToWidth(true);
scrollPane.setFitToHeight(true);
FlowPane flowPane = new FlowPane();
flowPane.setStyle("-fx-background-color: blue");
flowPane.setPadding(new Insets(10, 10, 10, 10));
flowPane.setHgap(10);
flowPane.setVgap(10);
Rectangle rect1 = new Rectangle(100, 100, Color.RED);
Rectangle rect2 = new Rectangle(100, 100, Color.RED);
Rectangle rect3 = new Rectangle(100, 100, Color.RED);
Rectangle rect4 = new Rectangle(100, 100, Color.RED);
flowPane.getChildren().add(rect1);
flowPane.getChildren().add(rect2);
flowPane.getChildren().add(rect3);
flowPane.getChildren().add(rect4);
scrollPane.setContent(flowPane);
primaryStage.setScene(new Scene(scrollPane, 500, 500));
primaryStage.show();
}
}
i) Which property of scrollPane should I check to get the default value for displaying scrollbar?
ii) How will modify the code so as to display scrollbar at a desired point (while resizing)?