📅  最后修改于: 2020-10-14 05:49:29             🧑  作者: Mango
HBox布局窗格将节点排列在一行中。它由javafx.scene.layout.HBox类表示。我们只需要实例化HBox类即可创建HBox布局。
下表提供了类的属性及其设置方法。
Property | Description | Setter Methods |
---|---|---|
alignment | This represents the alignment of the nodes. | setAlignment(Double) |
fillHeight | This is a boolean property. If you set this property to true the height of the nodes will become equal to the height of the HBox. | setFillHeight(Double) |
spacing | This represents the space between the nodes in the HBox. It is of double type. | setSpacing(Double) |
HBox类包含以下两个构造函数。
package application;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class Label_Test extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Button btn1 = new Button("Button 1");
Button btn2 = new Button("Button 2");
HBox root = new HBox();
Scene scene = new Scene(root,200,200);
root.getChildren().addAll(btn1,btn2);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
package application;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class Label_Test extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Button btn1 = new Button("Button 1");
Button btn2 = new Button("Button 2");
HBox root = new HBox();
Scene scene = new Scene(root,200,200);
root.getChildren().addAll(btn1,btn2);
root.setSpacing(40);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}