java - 使所有元素(包括 2 个列表视图)在 JavaFX 中一起滚动
问题描述
我有一个 VBox,在 VBox 中有一些元素,包括 3 个标题(3 个堆栈窗格)和 2 个列表视图,是否可以让 VBox 中的所有内容一起滚动?
这是我的应用程序的图像
这是此视图的 FXML 代码
<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>
解决方案
我设法通过用 scrollPane 包装 VBox 并设置来使整个 VBox 一起滚动scrollPane.setFitToWidth(true);
推荐阅读
- java - 使用 JDK>=9 远程调试 yajsw 包装的应用程序
- nativescript-angular - Nativescript-angular tns 运行失败并出现错误错误:无法解析 ApplicationModule 的所有参数
- javascript - React 中的 Axios 请求问题
- amazon-redshift - 我们是否可以使用 debezium 在目标数据库(redshift)中创建每日快照作为行
- java - 如何将多个枚举数据写入单个 pojo 并将其作为列表返回
- jhipster - 在 jhipster 单体应用程序上创建角色层次结构
- azure - ##[错误]未处理:句柄不是 Azure DevOps 构建管道中的缓冲区 CopyFilesOverSSH
- javascript - 从渲染画布而不是整个窗口中获取坐标
- html - 使用令人敬畏的字体提高可访问性来传达含义
- python - 如何通过外键返回数组中的整个表行以及如何从 django 模型中的模板访问