簡體   English   中英

HBox不會填充邊框中央的可用空間

[英]HBox doesn't fill the available space in center of borderpane

我使用以下代碼將HBox放置在BorderPane的中心,這是DialogDialogPane上的唯一直接Node

    public GameDialog(Player[] players) {
          setTitle("Spiel eintragen");
          setWidth(WIDTH);
          setHeight(HEIGHT);

          createLeftBox();
          createRightBox(players);

          // Center
          this.center = new HBox(leftBox, rightBox);
          center.setStyle("-fx-border-color: #00ff00;");
          center.getChildren()
                .forEach(b -> HBox.setMargin(b, INSETS));

          // Bottom
          this.btnOk = new Button("ok");
          this.btnCancel = new Button("abbrechen");
          this.bottom = new HBox(btnOk, btnCancel);
          bottom.getChildren()
                .forEach(b -> HBox.setMargin(b, INSETS));

          // Pane
          this.pane = new BorderPane(center);
          pane.setBottom(bottom);
          pane.setPrefSize(WIDTH, HEIGHT);
          getDialogPane().setPrefSize(WIDTH, HEIGHT);
          getDialogPane().getChildren().add(pane);
          ...
    }

    private void createLeftBox() {
      // Points spinner
      List<Integer> points = Stream.iterate(0, Util::increment)
                                   .limit(MAX_POINTS)
                                   .collect(Collectors.toList());
      this.spPoints = new Spinner<>(observableArrayList(points));

      // Solo combobox
      List<Solotype> soli = Arrays.asList(Solotype.values());
      this.cbSolo = new ComboBox<>(observableArrayList(soli));
      cbSolo.setOnAction(e -> changed());

      // Bock checkbox
      this.chBock = new CheckBox("Bock");

      // Left box
      leftBox = new VBox(spPoints, cbSolo, chBock);
      leftBox.getChildren()
             .forEach(n -> VBox.setMargin(n, INSETS));

      leftBox.setStyle("-fx-border-color: #ff0000");
   }

   private void createRightBox(Player[] players) {
      List<Player> playerlist = Arrays.asList(players);
      // Right box
      rightBox = new VBox();
      List<Node> rightChildren = rightBox.getChildren();
      this.playerBoxes = playerlist.stream()
                                   .collect(toMap(p -> p,
                                            p -> new HBox(4)));
      this.players = playerlist.stream()
                               .collect(toMap(p -> p,
                                              this::createToggleGroup));
      playerBoxes.values()
                 .stream()
                 .peek(rightChildren::add)
                 .forEach(b -> VBox.setMargin(b, INSETS));

      rightBox.setStyle("-fx-border-color: #ff0000");
   }

我的類GameDialog擴展了javafx類Dialog<R> 但是,位於BorderPane中心的HBox不會填充所有可用空間。 它看起來像這樣:

對話框的屏幕截圖

我試圖在幾個H-Box和VBoxes上設置setMinWidth,setMinHeight,setPrefSize,setFillWidth(true)和setFillHeight(true)。 沒有改變。 我只是不了解這種行為。 有任何想法嗎?

我無法完全重新創建您的示例(由於缺少一些代碼,因此我使用了TextField而不是那些切換組),但是此解決方案取得了一些成功。

而不是使用:

getDialogPane().getChildren().add(pane);

采用:

getDialogPane().setContent(pane);

並且控件應使用所有可用空間。


在此處輸入圖片說明

(我還刪除了首選寬度和高度的設置,因此圖像要小一些。設置pane的首選大小不會改變任何方式。)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM