首页 文章

JavaFX FXML Center BorderPane底部

提问于
浏览
0

我有一个 Button ,我想把它放在我的BorderPane底部并居中 . 我想用 FXML 来实现这个目标 .

这是我的BorderPane的底部:

<bottom>
            <Button>
                <text>
                    Center this button
                </text>
            </Button>
        </bottom>

完整的 FXML (没有导入):

<BorderPane id="BorderPane" xmlns:fx="http://javafx.com/fxml/1">
        <top>
            <HBox>
                <BorderPane.margin>
                    <Insets left="15" right="15" top="15"/>
                </BorderPane.margin>
                <spacing>
                    5
                </spacing>
                <Label>
                    <padding>
                        <Insets top="5" right="5"/>
                    </padding>
                    <text>
                        Y-Axis:
                    </text>
                </Label>
                <TextField>
                    <text>
                        10
                    </text>
                </TextField>

                <Label>
                    <padding>
                        <Insets top="5" left="15" right="5"/>
                    </padding>
                    <text>
                        X-Axis:
                    </text>
                </Label>
                <TextField>
                    <text>
                        10
                    </text>
                </TextField>
            </HBox>
        </top>

        <bottom>
            <Button>
                <text>
                    Center this button
                </text>
            </Button>
        </bottom>

结果:

enter image description here

有没有任何Tag用FXML实现这一目标?或者我必须使用JAVA吗?谢谢 .

1 回答

  • 3

    使用 BorderPane.alignment

    <bottom>
        <Button BorderPane.alignment="CENTER">
            <text>
                Center this button
            </text>
        </Button>
    </bottom>
    

相关问题