java - 我将如何移动我的按钮,以便它们以水平方式显示在我的标题下方?
问题描述
目前,我在菜单屏幕上创建的按钮(存储在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);
解决方案
推荐阅读
- elasticsearch - Elasticsearch - 如何为摄取管道中的内部字段提供价值
- python - Django 在运行服务器时报错
- python - 设置Word2Vec的参数为一个实例
- regex - 在正则表达式中什么是变长lookbehind-assertion?
- python - Pandas 访问数据框中的列表元素?
- python - PyCharm 专业版中的自动格式化导入
- python - 与 FastAPI 中的 flask.copy_current_request_context 相同吗?
- django - 如果字段有数据,Django 得到 True/False
- python - 在python中运行而不刷新屏幕
- ms-access - MS-Access - 报告分组