0

我有一个包含 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,但我一直得到这个:

TabPanel 布局

4

2 回答 2

1

<ScrollPane fx:id="scrollPane" fitToHeight="true" fitToWidth="true">
...

帮助?

于 2013-07-23T09:47:09.553 回答
0

好的,我想出了如何获得所需的行为。使用 AnchorPane 可以强制子节点占用相对于父节点的空间。我分享代码以防有人发现它有用:

<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>

结果:

期望的行为

于 2013-07-26T23:58:47.873 回答