[英]Right align Button inside HBox inside .fxml file
我有这个代码:
public class DogApp extends Application {
@Override
public void start(Stage stage) throws Exception {
Parent gridPane = FXMLLoader.load(getClass().getResource("Dog.fxml"));
Scene scene = new Scene(gridPane, 300, 200);
stage.setScene(scene);
stage.setTitle("Dog bark");
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.geometry.Insets?>
<GridPane xmlns:fx="http://javafx.com/fxml/1" fx:controller="DogListener"
hgap="10" vgap="10" alignment="CENTER">
<padding>
<Insets top="25" right="25" bottom="10" left="25"/>
</padding>
<Label text="Distance:" GridPane.columnIndex="0" GridPane.rowIndex="0"/>
<TextField fx:id="distance" GridPane.columnIndex="1" GridPane.rowIndex="0"/>
<Label text="Paws:" GridPane.columnIndex="0" GridPane.rowIndex="1"/>
<TextField fx:id="pawsNumber" GridPane.columnIndex="1" GridPane.rowIndex="1"/>
<Label text="DPP:" GridPane.columnIndex="0" GridPane.rowIndex="2"/>
<TextField fx:id="distancePerPaw" editable = "false"
GridPane.columnIndex="1" GridPane.rowIndex="2"/>
<HBox GridPane.columnIndex="0" GridPane.rowIndex="3" GridPane.columnSpan="2">
<Button text="Calculate" onAction="#calculateButtonClicked"
alignment="BASELINE_RIGHT"/>
</HBox>
</GridPane>
表明:
我需要将Calculate
按钮定位在HBox
的右侧:
我试过了
alignment="BASELINE_RIGHT"
但它没有用。
就像@anko 所说,使用<HBox alignment="BASELINE_RIGHT" GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.halignment="RIGHT" GridPane.rowIndex="3">
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<GridPane alignment="CENTER" hgap="10" vgap="10" xmlns="http://javafx.com/javafx/15.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="DogListener">
<padding>
<Insets bottom="10" left="25" right="25" top="25" />
</padding>
<Label text="Distance:" GridPane.columnIndex="0" GridPane.rowIndex="0" />
<TextField fx:id="distance" GridPane.columnIndex="1" GridPane.rowIndex="0" />
<Label text="Paws:" GridPane.columnIndex="0" GridPane.rowIndex="1" />
<TextField fx:id="pawsNumber" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label text="DPP:" GridPane.columnIndex="0" GridPane.rowIndex="2" />
<TextField fx:id="distancePerPaw" editable="false" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<HBox alignment="BASELINE_RIGHT" GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.halignment="RIGHT" GridPane.rowIndex="3">
<Button alignment="CENTER" onAction="#calculateButtonClicked" text="Calculate" />
</HBox>
<columnConstraints>
<ColumnConstraints />
<ColumnConstraints />
</columnConstraints>
<rowConstraints>
<RowConstraints />
<RowConstraints />
<RowConstraints />
<RowConstraints />
</rowConstraints>
</GridPane>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.