繁体   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