Why doesn't this align my HBox in the middle? I have to put 2 buttons in my HBox and align the HBox in the middle of the screen so I get those 2 buttons right in the middle next to each otherl.
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class firstwindow extends Application {
Button CreateButton;
Button SeeButton;
public static void main (String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
//Setting title
primaryStage.setTitle("Basketball stats tracker");
//creating buttons
CreateButton = new Button("Create");
SeeButton = new Button("See");
//Creating HBox
HBox centerButtons = new HBox(15); //15 is the space between box elements
centerButtons.getChildren().addAll(CreateButton, SeeButton);
//creating layout
StackPane layout = new StackPane();
layout.getChildren().add(centerButtons);
StackPane.setAlignment(centerButtons, Pos.CENTER);
//creating scene
Scene scene = new Scene(layout, 600, 400);
//creating Stage
primaryStage.setScene(scene);
primaryStage.show();
}
}
Can you please guys help me with that?