package javafx_layoutpanes;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.stage.Stage;
/**
*
* @web http://java-buddy.blogspot.com/
*/
public class JavaFX_LayoutPanes extends Application {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("java-buddy.blogspot.com: StackPane");
Group root = new Group();
double width = 400;
double height = 300;
Scene scene = new Scene(root, width, height, Color.WHITE);
StackPane stackPane = new StackPane();
stackPane.setPrefSize(width, height);
stackPane.setAlignment(Pos.CENTER);
Button cbutton = new Button("Center Button");
Button button = new Button("Button");
Text text = new Text("Text");
stackPane.getChildren().addAll(cbutton, button, text);
root.getChildren().add(stackPane);
primaryStage.setScene(scene);
primaryStage.show();
}
}
Compare with Create StackPane using FXML.