我想将ListView放在ScrollPane旁边。但是,当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>