有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java JavaFX如何使GridPane适合ScrollPane父级?

我需要一个带有网格的页面,在其中输入一些数据,所以,使用SceneBuilder,我将一个网格窗格放在一个锚面板中。我需要的网格窗格有很大的高度,所以我把它包在一个滚动窗格中,使滚动窗格适合锚烷。 但现在,当我展开窗口时,网格窗格的大小不会像不适合滚动窗格那样调整。 如何在调整窗口大小时调整gridpane的大小


共 (1) 个答案

  1. # 1 楼答案

    ScrollPanefitToWidth属性设置为true,并确保ScrollPane的两个锚都已设置
    您可能还需要对GridPane列使用适当的约束来调整GridPane的子级的大小

    示例

    <AnchorPane xmlns:fx="http://javafx.com/fxml/1">
        <children>
            <ScrollPane fitToWidth="true"
                        AnchorPane.leftAnchor="10"
                        AnchorPane.rightAnchor="10"
                        AnchorPane.topAnchor="10"
                        AnchorPane.bottomAnchor="10">
                <content>
                    <GridPane hgap="10">
                        <padding>
                            <Insets topRightBottomLeft="10"/>
                        </padding>
                        <columnConstraints>
                            <ColumnConstraints /> 
                            <ColumnConstraints fillWidth="true" hgrow="ALWAYS" /> 
                        </columnConstraints>
                        <children>
                            <Text text="Family Name:"/>
                            <TextField GridPane.columnIndex="1"/>
                        </children>
                    </GridPane>
                </content>
            </ScrollPane>
        </children>
    </AnchorPane>