我试图将我的两个按钮直接放在我的标签下,并将所有内容都放在我的表格上 . 目前一切都只是印在一条线上 .
@Override public void start(Stage primaryStage)抛出Exception {
HBox hb = new HBox();
hb.setSpacing(15);
hb.setPadding(new Insets(15, 20, 5, 10));
hb.setAlignment(Pos.CENTER);
Label label = new Label("Greetings! Would you like to purchase cruise ticket for a family of two?");
hb.getChildren().add(label);
button1 = new Button("Yes");
hb.getChildren().add(button1);
button1.setOnAction(this);
button2 = new Button("No");
hb.getChildren().add(button2);
button2.setOnAction(this);
Scene scene = new Scene(hb, 550, 250);
primaryStage.setTitle("Cruise for two!");
primaryStage.setScene(scene);
primaryStage.show();
}
2 回答
HBox
将始终将其子项排列在水平行中 . 通过将Label
添加到HBox
,JavaFX正在做你正在告诉它的事情 .您还有
VBox
,它垂直排列节点 . 在VBox
中,添加Label
,然后添加HBox
;他们将在Label
下安排HBox
.