Issue
I have a VBox, and within the VBox are some elements including 3 headers (3 stack panes) and 2 list views, is it possible to make everything in the VBox scroll together?
Here is an image of my application
This is the FXML code for this view
<VBox xmlns="http://javafx.com/javafx/11" xmlns:fx="http://javafx.com/fxml/1">
<StackPane prefHeight="30.0" prefWidth="200.0" styleClass="stack-welcome" VBox.vgrow="NEVER">
<children>
<!-- WELCOME MESSAGE -->
<Label styleClass="label-welcome" text="Hi! I'm Volant :)" />
</children>
</StackPane>
<StackPane prefHeight="15.0" prefWidth="200.0" styleClass="stack-header" VBox.vgrow="NEVER">
<children>
<Label styleClass="label-header" text="TRIP LIST" />
</children>
</StackPane>
<StackPane prefHeight="15.0" prefWidth="200.0" styleClass="trip-list-header" style="-fx-border-width: 0px 0px 2px 0px" VBox.vgrow="NEVER">
<children>
<Label styleClass="label-header" text="UPCOMING TRIPS" />
</children>
</StackPane>
<ListView fx:id="tripListViewUpcoming" prefWidth="247.0" style="-fx-background-color: #fff;" VBox.vgrow="ALWAYS" />
<StackPane prefHeight="15.0" prefWidth="200.0" styleClass="trip-list-header" style="-fx-border-width: 2px 0px 2px 0px" VBox.vgrow="NEVER">
<children>
<Label styleClass="label-header" text="PAST TRIPS" />
</children>
</StackPane>
<ListView fx:id="tripListViewPast" prefWidth="247.0" style="-fx-background-color: #fff;" VBox.vgrow="ALWAYS" />
</VBox>
Solution
I manged to make the whole VBox scroll together by wrapping the VBox with a scrollPane and setting scrollPane.setFitToWidth(true);
Answered By - Meowmi