首页 > 解决方案 > 我将如何移动我的按钮,以便它们以水平方式显示在我的标题下方?

问题描述

目前,我在菜单屏幕上创建的按钮(存储在VBoxes和中HBoxes)垂直放置在我的标题上方。我将如何移动它们以便将它们水平放置在我的标题下方?这是我到目前为止的代码:

    Scene menu, game, help, dWin, aWin;       
    @Override
    public void start(Stage primaryStage) throws Exception {
                //Menu Scene
        // set up background border pane (Top/Left/Right/Center/Bottom)
        BorderPane menuBorder = new BorderPane();
                menuBorder.setPadding(new Insets(15, 520, 100, 150));
        // Screen Size
        int menuWidth = 1000;
        int menuHeight = 700;

                StackPane menuBackgroundImgContainer = new StackPane();
                ImageView menuBgImage = new ImageView("vikingFire.jpg");//background image
                menuBgImage.setFitHeight(menuHeight + 10);
                menuBgImage.setFitWidth(menuWidth + 10);
                menuBackgroundImgContainer.getChildren().addAll(menuBgImage,menuBorder);
                menu = new Scene(menuBackgroundImgContainer, menuWidth,menuHeight);

                Button buttonPlayGame = new Button("Play Game"); // play game button
                buttonPlayGame.resize(menuWidth*.05, menuHeight*.1);
                buttonPlayGame.setStyle("-fx-background-color: #B8860B");
                buttonPlayGame.setOnMouseEntered(highlightOnPlayGame -> { 
            // highlight
            buttonPlayGame.setStyle("-fx-background-color: #FFD700");
        });
        buttonPlayGame.setOnMouseExited(highlightOff -> {
            buttonPlayGame.setStyle("-fx-background-color: #B8860B");
        });
                //
                Button button1Player = new Button("Play 1 player"); // play game button
                button1Player.resize(menuWidth*.05, menuHeight*.1);
                button1Player.setStyle("-fx-background-color: #B8860B");
                button1Player.setOnMouseEntered(highlightOnPlayGame -> { 
            // highlight
            button1Player.setStyle("-fx-background-color: #FFD700");
        });
        button1Player.setOnMouseExited(highlightOff -> {
            button1Player.setStyle("-fx-background-color: #B8860B");
        });
                Button button2Player = new Button("Play 2 player"); // play game button
                button2Player.resize(menuWidth*.05, menuHeight*.1);
                button2Player.setStyle("-fx-background-color: #B8860B");
                button2Player.setOnMouseEntered(highlightOnPlayGame -> { 
            // highlight
            button2Player.setStyle("-fx-background-color: #FFD700");
        });
        button2Player.setOnMouseExited(highlightOff -> {
            button2Player.setStyle("-fx-background-color: #B8860B");
        });
                //
                Button buttonHelp = new Button("Help Screen"); // goes to help screen
                buttonHelp.resize(menuWidth*.05, menuHeight*.1);
                buttonHelp.setStyle("-fx-background-color: #B8860B");
                buttonHelp.setOnMouseEntered(highlightOnHelpScreen -> { 
            // highlight
            buttonHelp.setStyle("-fx-background-color: #FFD700");
        });
        buttonHelp.setOnMouseExited(highlightOff -> {
            buttonHelp.setStyle("-fx-background-color: #B8860B");
        });
                Text menuTitle = new Text("King's Table");
                menuTitle.setFont(new Font(textFont, 80));
                menuTitle.setFill(Color.ORANGERED);
                menuTitle.setStroke(Color.RED);
                buttonPlayGame.setOnAction(clickToGame -> {
                    primaryStage.setScene(game);
                    startGameTime = System.nanoTime(); // start game timer
                        });//click button go to Game screen

                buttonHelp.setOnAction(clickToHelpScreen -> primaryStage.setScene(help));//click button go to Help screen
                VBox layout1 = new VBox(20);
                layout1.getChildren().addAll(buttonPlayGame, buttonHelp, button1Player, button2Player, menuTitle);
                menuBorder.setBottom(layout1);

标签: javajavafx

解决方案


推荐阅读