0

我正在尝试拥有一个带有两个 GridPanel 的 HBox,一个较大的在左侧,一个较小的在右侧(从场景右侧的末端开始)但是我无法将它们放在我想要的位置。这就是它现在的样子。如您所见,红色的 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);

测试按钮面板应该在左边,分数面板是红色的,应该在右边。我希望你能帮助我。非常感谢你。=)

4

0 回答 0