Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fit FlowPane into ScrollPane

I using this code to fit 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?

like image 545
Peter Penzov Avatar asked Sep 15 '25 06:09

Peter Penzov


1 Answers

There are methods of ScrollPane meant to do this:

scrollPane.setFitToWidth(true);
scrollPane.setFitToHeight(true);
like image 152
Someone Avatar answered Sep 17 '25 22:09

Someone