java - HBox 未填充边框中心的可用空间

标签 java javafx

我放置了 HBox进入 BorderPane 的中心,那就是唯一直接NodeDialogPane上我的Dialog通过使用此代码:

    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");
   }

我的类(class)GameDialog扩展了 javafx 类 Dialog<R> 。然而HBoxBorderPane 的中心没有填满所有可用空间。它看起来就像这样:

Screenshot of the Dialog

我尝试在几个水平框和垂直框上设置 MinWidth、setMinHeight、setPrefSize、setFillWidth(true) 和 setFillHeight(true)。没有改变。我只是不明白这种行为。有什么想法吗?

最佳答案

我无法完全重新创建您的示例(由于缺少一些代码,我使用 TextField 而不是那些切换组),但此解决方案取得了一些成功。

而不是使用:

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

用途:

getDialogPane().setContent(pane);

控件应该使用所有可用空间。

<小时/>

enter image description here

(我还删除了首选宽度和高度的设置,因此图像稍小一些。设置 Pane 的首选大小不会以任何方式改变任何内容。)

关于java - HBox 未填充边框中心的可用空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38161137/

相关文章:

java - HttpAsyncTask 返回 null 作为数据

java - FXML:将 TableViews 项目属性绑定(bind)到 Controller

单击按钮时的 JavaFX 新场景

java - JVM 错误 : Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

java - Spring Security 有条件的 default-target-url

java - 无法从单选按钮获取值

java - 如何创建 2D char 数组的 2D 数组?

Java/安卓 : LinkedList race condition

JavaFx:从事件处理程序访问对象

JavaFX 圆形镂空