Javafx : SplitPane resize children

2019-08-03 16:06发布

I fave an .fxml file, in which I have added some TitledPane but I cannot resize them in the application. Here is the code:

<ScrollPane AnchorPane.topAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.bottomAnchor="0.0"
            AnchorPane.leftAnchor="0.0">
    <SplitPane orientation="VERTICAL" fx:id="splitPane">
        <TitledPane>
            <TextArea fx:id="taTop" wrapText="true" editable="false" prefHeight="100"/>
        </TitledPane>
        <TitledPane>
            <TableView fx:id="tableFrist" minHeight="120" maxHeight="120">
                <columns>
                    <TableColumn fx:id="column" prefWidth="200"/>
                </columns>
            </TableView>
        </TitledPane>
        <TitledPane>
            <TreeTableView fx:id="tableSecond">
                <columns>
                    <TreeTableColumn fx:id="columnTreeS" prefWidth="200"/>
                </columns>
            </TreeTableView>
        </TitledPane>
        <TitledPane>
            <TreeTableView fx:id="tableThird">
                <columns>
                    <TreeTableColumn fx:id="columnTreeT" prefWidth="200"/>
                </columns>
            </TreeTableView>
        </TitledPane>
        <TitledPane>
            <TextArea fx:id="taBot" wrapText="true" editable="false"/>
        </TitledPane>
    </SplitPane>
</ScrollPane>

What did I miss, or why I cannot resise the panes?

1条回答
啃猪蹄的小仙女
2楼-- · 2019-08-03 16:50

Set the fitToHeight and fitToWidth attributes to true for ScrollPane:

https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/ScrollPane.html#fitToHeightProperty

If true and if the contained node is a Resizable, then the node will be kept resized to match the height of the ScrollPane's viewport. If the contained node is not a Resizable, this value is ignored.

Change

<ScrollPane AnchorPane.topAnchor="0.0" 
            AnchorPane.rightAnchor="0.0" 
            AnchorPane.bottomAnchor="0.0"
            AnchorPane.leftAnchor="0.0">

to

<ScrollPane AnchorPane.topAnchor="0.0" 
            AnchorPane.rightAnchor="0.0" 
            AnchorPane.bottomAnchor="0.0"
            AnchorPane.leftAnchor="0.0" 
            fitToHeight="true" 
            fitToWidth="true">
查看更多
登录 后发表回答