Can';t在中心对齐HBox(JavaFX) 为什么不把我的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(); } }

Can';t在中心对齐HBox(JavaFX) 为什么不把我的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(); } },java,alignment,hbox,Java,Alignment,Hbox,你们能帮我一下吗?From:“内容的对齐方式由对齐属性控制,默认为Pos.TOP_LEFT。”Java类名的惯例是每个单词都有大写字母;例如,您的类可能被命名为FirstWindow,而不是FirstWindow。另外,请注意,实例变量名使用camelCase,需要有privateaccess-CreateButton需要是CreateButton,等等。谢谢,我是在设置节点的对齐方式(使用StackPane.setAlignment),而不是使用setAlignment对齐整个HBox

你们能帮我一下吗?

From:“内容的对齐方式由对齐属性控制,默认为Pos.TOP_LEFT。”Java类名的惯例是每个单词都有大写字母;例如,您的类可能被命名为
FirstWindow
,而不是
FirstWindow
。另外,请注意,实例变量名使用camelCase,需要有
private
access-
CreateButton
需要是
CreateButton
,等等。谢谢,我是在设置节点的对齐方式(使用StackPane.setAlignment),而不是使用setAlignment对齐整个HBox