我正在尝试创建游戏的第一个窗口,并创建一个放置在第一个屏幕中心的菜单。
BorderPane bp = new BorderPane();
Button Start = new Button("Start");
Button Mute = new Button("Mute");
Button Exit = new Button("Quit");
Button Options = new Button("Options");
/*
* Vbox in Center for buttons:
* (non-Javadoc)
* @see javafx.application.Application#start(javafx.stage.Stage)
*/
public void start(Stage primaryStage) {
VBox vb = new VBox(100);
vb.getChildren().addAll(Start,Options,Mute,Exit);
vb.setMargin(Start, new Insets(0,0,0,15));
vb.setMargin(Options, new Insets(0,0,0,15));
vb.setMargin(Mute, new Insets(0,0,0,15));
vb.setMargin(Exit, new Insets(0,0,0,15));
bp.setCenter(vb);
Scene scene = new Scene(bp, WIDTH, HEIGHT);
primaryStage.setTitle("Tetris");
primaryStage.setScene(scene);
primaryStage.show();
}
答案 0 :(得分:0)
这里的关键是vb.setMaxSize(Control.USE_PREF_SIZE, Control.USE_PREF_SIZE);
。我在VBox
上设置了背景颜色,以便您可以更好地了解情况。
BorderPane bp = new BorderPane();
Button Start = new Button("Start");
Button Mute = new Button("Mute");
Button Exit = new Button("Quit");
Button Options = new Button("Options");
VBox vb = new VBox(100);
vb.setStyle("-fx-background-color: yellow");
vb.getChildren().addAll(Start,Options,Mute,Exit);
vb.setMargin(Start, new Insets(0,0,0,15));
vb.setMargin(Options, new Insets(0,0,0,15));
vb.setMargin(Mute, new Insets(0,0,0,15));
vb.setMargin(Exit, new Insets(0,0,0,15));
vb.setMaxSize(Control.USE_PREF_SIZE, Control.USE_PREF_SIZE);
bp.setCenter(vb);
Scene scene = new Scene(bp, 500, 720);
primaryStage.setTitle("Tetris");
primaryStage.setScene(scene);
primaryStage.show();