我有一个简单的登录表单。请参阅下面的原型:
我决定使用GridPane作为布局容器,无法通过居中和跨度提交按钮对齐LOGO。
那是我的login.fxml:
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.Button?>
<GridPane alignment="CENTER" hgap="20" vgap="10">
<ImageView fitHeight="82.0" fitWidth="296.0" pickOnBounds="true" preserveRatio="true" GridPane.rowIndex="0" GridPane.columnIndex="0" GridPane.columnSpan="2">
<Image url="logo.png"/>
</ImageView>
<Label text="login:" GridPane.rowIndex="1" GridPane.columnIndex="0"/>
<Label text="password:" GridPane.rowIndex="1" GridPane.columnIndex="1"/>
<TextField prefWidth="200" prefHeight="20" GridPane.rowIndex="2" GridPane.columnIndex="0"/>
<TextField prefWidth="200" prefHeight="20" GridPane.rowIndex="2" GridPane.columnIndex="1"/>
<Button text="submit" GridPane.rowIndex="3" GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.hgrow="ALWAYS" GridPane.fillWidth="true" />
</GridPane>
这就是我得到的: