为什么这不能将HBox对准中间? 我必须在HBox中放置2个按钮,并将HBox对准屏幕的中间,这样我才能将这2个按钮彼此相邻地放在中间。
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();
}
}
你们能帮我吗?