我正在试图让一个带有两个GridPanel的HBox,左边一个更大的一个,右边一个更小的一个(从右边的场景开始)然而我无法让他们处于我的位置想要。 This is how it looks right now.正如您所看到的,红色GridPane位于另一个之上。红色面板应该全部等待到右边。 此外,即使某些按钮或文本添加到任何一个GridPanes中,我希望它们保持相同的位置。
这是我的代码:
//TEST BUTTONS PANEL
testButtonPane = new GridPane();
testButtonPane.setHgap(10);
testButtonPane.setVgap(9);
testButtonPane.setPadding(new Insets(140, 100, 0, 100));
questionLabel = new Label("Question:");
questionLabel.setPrefWidth(500.0);
questionLabel.setPrefHeight(50.0);
questionLabel.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522");
testButtonPane.add(questionLabel,1,1);
testButtonPane.add(backButton,1,10);
backButton = new Button("BACK");
backButton.setOnAction(e -> primaryStage.setScene(sceneCreateTest));
backButton.setPrefWidth(140.0);
backButton.setPrefHeight(50.0);
backButton.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522");
testButtonPane.add(backButton,1,10);
//SCORE PANEL
scoreButtonPane = new GridPane();
scoreButtonPane.setHgap(10);
scoreButtonPane.setVgap(9);
scoreButtonPane.setPadding(new Insets(10, 10, 0, 10));
scoreButtonPane.setStyle("-fx-background-color: #AE3522;-fx-border-color: black");
statusTitleLabel = new Label("STATUS");
statusTitleLabel.setPrefWidth(160.0);
statusTitleLabel.setPrefHeight(50.0);
statusTitleLabel.setStyle("-fx-font: 30 timesnewroman; -fx-text-fill:black ;");
scoreButtonPane.add(statusTitleLabel,1,1,2,1);
scoreLabel = new Label("Score: ");
scoreLabel.setPrefWidth(130.0);
scoreLabel.setPrefHeight(50.0);
scoreLabel.setStyle("-fx-font: 20 timesnewroman; -fx-text-fill:black ;");
scoreButtonPane.add(scoreLabel,1,2);
timerLabel = new Label("Time: ");
timerLabel.setPrefWidth(130.0);
timerLabel.setPrefHeight(50.0);
timerLabel.setStyle("-fx-font: 20 timesnewroman; -fx-text-fill:black ;");
scoreButtonPane.add(timerLabel,1,3);
QInLabel = new Label("Question: ");
QInLabel.setPrefWidth(130.0);
QInLabel.setPrefHeight(50.0);
QInLabel.setStyle("-fx-font: 20 timesnewroman; -fx-text-fill:black ;");
scoreButtonPane.add(QInLabel,1,4);
//Makes possible to have two panes in the same scene/layout
HBox hBoxTest = new HBox();
hBoxTest.setSpacing(10.0);
hBoxTest.setPadding(new Insets(140,10,50,10));
hBoxTest.getChildren().addAll(testButtonPane, scoreButtonPane);
测试按钮面板应位于左侧,记分面板为红色,应位于右侧。我希望你能帮助我。非常感谢你提前。 =)