listview - 增加 ListView 宽度以适应内容并删除水平滚动条
问题描述
我想在 ScrollPane 旁边放置一个 ListView。但是当 ListView 的动态内容太宽时,我希望 ListView 变得更宽以适应它的内容。在提供的图像中,您可以看到它如何创建滚动条而不是扩大 ListView。
由于我是 JavaFX 新手,我不知道如何实现这种行为。如何使 ListView 变得更宽以自动适应其内容?这可以完全在 FXML 中完成吗?
这是我关注的 UI 部分的 FXML:
<HBox prefHeight="480.0" prefWidth="640.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="28.0">
<children>
<ListView fx:id="componentList" prefHeight="-1.0" prefWidth="-1.0" HBox.hgrow="NEVER" />
<ScrollPane hbarPolicy="ALWAYS" pannable="true" prefHeight="200.0" prefWidth="200.0" vbarPolicy="ALWAYS" HBox.hgrow="ALWAYS">
<content>
<AnchorPane id="Content" minHeight="0.0" minWidth="0.0" prefHeight="2000.0" prefWidth="2000.0">
<children>
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="200.0" layoutX="67.0" layoutY="45.0" stroke="BLACK" strokeType="INSIDE" width="200.0" />
</children>
</AnchorPane>
</content>
</ScrollPane>
</children>
</HBox>
解决方案
推荐阅读
- matlab - 如何在矩阵中查找没有特定行的 NaN 元素的列的索引?
- python - 如何在熊猫中选择一个级别和所有子级别(和项目)?
- ios - 如何为 Data swift 添加扩展?
- java - 如何在边框底部的每个角落放置两个按钮
- xaml - 如何使用带有 Xamarin Forms 的列表视图单元格的选定项目上的带有单选按钮的 Checked 绑定?
- matlab - 左矩阵除以向量
- angularjs - 如何使用量角器测试是否显示 AngularJS md-tooltip
- ruby - Ruby popen3 - 如何防止重复写入标准输入导致超时?
- office-js - Microsoft Teams 中未显示管理员管理的 Office Web 插件
- php - 事务在 CodeIgniter 中无法正常工作