我有一个包含 ScrollPanel 的 fxml 文件,用于在 TabPanel 内显示图像:
<Tab text="Example" fx:id="liveTab" fx:controller="me.example.ExampleController" xmlns:fx="http://javafx.com/fxml">
<content>
<HBox prefHeight="600.0" prefWidth="1200.0">
<children>
<FlowPane prefHeight="600.0" prefWidth="400.0">
<children>
<ScrollPane prefHeight="580.0" prefWidth="200.0">
<content>
<ListView fx:id="listView" prefHeight="580.0" prefWidth="190.0">
<items>
<FXCollections fx:factory="observableArrayList">
</FXCollections>
</items>
</ListView>
</content>
</ScrollPane>
<ScrollPane prefHeight="580.0" prefWidth="200.0">
<content>
<ListView prefHeight="580.0" prefWidth="190.0">
<items>
<FXCollections fx:factory="observableArrayList">
</FXCollections>
</items>
</ListView>
</content>
</ScrollPane>
<HBox alignment="BOTTOM_RIGHT" prefHeight="20.0" prefWidth="400.0" spacing="10.0" GridPane.columnIndex="0" GridPane.rowIndex="2">
<Button text="Add"/>
<Button text="Remove"/>
</HBox>
</children>
</FlowPane>
<VBox>
<children>
<ScrollPane fitToHeight="true" fitToWidth="true">
<content>
<ImageView fx:id="imageContainer" pickOnBounds="true" preserveRatio="true">
<Image url="file:/C:/Users/Public/Pictures/Sample%20Pictures/Koala.jpg" preserveRatio="true" />
</ImageView>
</content>
</ScrollPane>
</children>
</VBox>
</children>
</HBox>
</content>
</Tab>
我希望 ImageView 占用包含选项卡的所有剩余空间,我尝试使用 fitToHeight="true" fitToWidth="true",并从 FlowPane 更改为 VBox,但我一直得到这个: