javafx.scene.control.ScrollPane是否可以占用选项卡面板中的剩余空间?
我有一个fxml文件,其中包含一个ScrollPanel,用于在TabPanel中显示图像:javafx.scene.control.ScrollPane是否可以占用选项卡面板中的剩余空间?,javafx,Javafx,我有一个fxml文件,其中包含一个ScrollPanel,用于在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"> &l
<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,但我一直得到以下结果:
有
...
帮助?好的,我知道如何获得所需的行为。使用锚烷可以强制子节点占据相对于父节点的空间。我共享代码,以防有人发现它有用:
<Tab text="Example" fx:id="liveTab" fx:controller="me.example.ExampleController" xmlns:fx="http://javafx.com/fxml">
<content>
<AnchorPane 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>
<AnchorPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="400.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<ScrollPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<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>
</AnchorPane>
</children>
</AnchorPane>
</content>
</Tab>
结果是:
它没有,父容器的长度是1200px,我的滚动面板有一个400px长的同级,我希望它向左移动800px,但它没有,它正在移动剩余的高度。@Amaury。那么您使用了错误的布局面板。尝试使用VBox而不是FlowPane。虽然它有助于使用HBox(我希望剩余的空间水平),但我仍然遇到同样的问题,如果我不指定prefWidth=“400.0”,滚动窗格的宽度仅为100px。我更新了问题,抱歉,我不得不继续使用其他功能。
<Tab text="Example" fx:id="liveTab" fx:controller="me.example.ExampleController" xmlns:fx="http://javafx.com/fxml">
<content>
<AnchorPane 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>
<AnchorPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="400.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<ScrollPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<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>
</AnchorPane>
</children>
</AnchorPane>
</content>
</Tab>