3
votes

I using this code to fir FlowPane into ScrollPane

FlowPane flowPane = new FlowPane(Orientation.HORIZONTAL);
ScrollPane scroll = new ScrollPane();
scroll.setContent(flowPane);
scroll.viewportBoundsProperty().addListener(new ChangeListener<Bounds>()
{
    @Override
    public void changed(ObservableValue<? extends Bounds> ov, Bounds oldBounds, Bounds bounds)
    {
        flowPane.setPrefWidth(bounds.getWidth());
        flowPane.setPrefHeight(bounds.getHeight());
    }
});

Unfortunately this maybe is not the best solution. Is there another more simple way to fit FlowPane into ScrollPane in Java 8?

2

2 Answers

10
votes

There are methods of ScrollPane meant to do this:

scrollPane.setFitToWidth(true);
scrollPane.setFitToHeight(true);
0
votes

Try setting maxWidth and maxHeoght properties of your flowPane to Double.MAX_VALUE either via CSS or via API so as to provide its maximal expansion whithin container:

flowPane.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);