2016-07-02 43 views
0

我放在一個HBoxBorderPane中心的中心填滿可用空間,這是對我的一個DialogDialogPane唯一直接Node通過使用此代碼:HBox中不borderpane

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-class Dialog<R>。但BorderPane中心的HBox未填滿所有可用空間。它只是看起來是這樣的:

Screenshot of the Dialog

我試圖setMinWidth,setMinHeight,setPrefSize,setFillWidth(真)和setFillHeight(真)在幾個H-和縱向方框的。沒有改變。我只是不明白這種行爲。有任何想法嗎?

+0

我假設'BorderPane'沒有你想象的那麼大。將一個可見的邊框放置到窗格中以將其可視化 – Dici

+0

我向其添加了一個邊框: pane.setStyle(「 - fx-border-color:#0000ff;」 +「-fx-border-width:4px;」 ); 但這沒有奏效。我沒有看到任何額外的邊框。 也許你是對的,它不是VBox小,而是BorderPane。在這種情況下,我仍然有同樣的問題:爲什麼BorderPane不能填滿所有可用空間? – David

+0

您不顯示與邊框窗格相關的代碼,因此很難知道 – Dici

回答

1

我無法完全重新創建您的示例(因爲某些代碼丟失,我使用了TextField而不是這些切換組),但在此解決方案中取得了一些成功。

而不是使用:

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

使用:

getDialogPane().setContent(pane); 

與對照組應使用所有可用空間。


enter image description here

(I也被去除的優選寬度和高度的設定,因此圖像是一個稍小一點。設置pane的優選尺寸沒有任何改變的任何方式。)