📅  最后修改于: 2020-10-14 05:50:03             🧑  作者: Mango
StackPane布局窗格将所有节点放入单个堆栈中,每个新节点都将放置在前一个节点的顶部。它由javafx.scene.layout.StackPane类表示。我们只需要实例化此类即可在应用程序中实现StackPane布局。
该类仅包含下面提供的一个属性及其setter方法。
Property | Description | Setter Method |
---|---|---|
alignment | It represents the default alignment of children within the StackPane’s width and height | setAlignment(Node child, Pos value) setAlignment(Pos value) |
该类包含以下两个构造函数。
package application;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Label_Test extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Button btn1 = new Button("Button 1 on bottom ");
Button btn2 = new Button("Button 2 on top");
StackPane root = new StackPane();
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);
}
}
输出: