英文:
Make all elements (including 2 list views) scroll together in JavaFX
问题
<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>
<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>
英文:
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>
答案1
得分: 0
我成功地通过使用滚动窗格包裹VBox,并设置 scrollPane.setFitToWidth(true);
来使整个VBox一起滚动。
英文:
I manged to make the whole VBox scroll together by wrapping the VBox with a scrollPane and setting scrollPane.setFitToWidth(true);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论