HBox没有填充边框中心的可用空间

时间:2016-07-02 14:18:48

标签: java javafx

我使用此代码将HBox放入BorderPane的中心,这是我Node的{​​{1}}上的唯一直接DialogPane

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"); } 扩展了javafx-class GameDialog。但是Dialog<R>中心的HBox并未填充所有可用空间。它看起来像这样:

Screenshot of the Dialog

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

1 个答案:

答案 0 :(得分:1)

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

而不是使用:

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

使用:

getDialogPane().setContent(pane);

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

enter image description here

(我也删除了首选宽度和高度的设置,因此图像略小。设置pane的首选大小不会改变任何方式。)