2017-06-21 50 views
0

我綁定Tile Property以使HomeTabCell動態調整它們的寬度和高度值。但HomeTabCell的寬度和高度保持不變。調整TilePane單元的大小

這是一種使它工作的方法,還是應該使用GridPane來代替?

for (int i = 0; i < room.getMaxPlayers(); i++) { 
      try { 
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/HomeTabCell.fxml")); 
        tilePane.getChildren().add(fxmlLoader.load()); 
        tilePane.prefTileWidthProperty().bind(centerRoomHBox.widthProperty().divide(2).subtract(3)); 
        tilePane.prefTileHeightProperty().bind(centerRoomHBox.heightProperty().divide(6/2)); 
        HomeTabCell box = (HomeTabCell) fxmlLoader.getController(); 
        box.setInfo(null, room.getMaxPlayers()); 
      } catch (IOException ex) { 
        bugsnag.notify(ex); 
      } 
} 

回答

0

我不得不做出anchorPaneHomeTabCellpublic然後將其綁定寬度和高度值。

for (int i = 0; i < room.getMaxPlayers(); i++) { 
         try { 
           FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/HomeTabCell.fxml")); 
           tilePane.getChildren().add(fxmlLoader.load()); 
           tilePane.prefTileWidthProperty().bind(centerRoomHBox.widthProperty().divide(2).subtract(3)); 
           tilePane.prefTileHeightProperty().bind(centerRoomHBox.heightProperty().divide(6/2)); 
           HomeTabCell box = (HomeTabCell) fxmlLoader.getController(); 
           box.anchorPane.prefWidthProperty().bind(centerRoomHBox.widthProperty().divide(2).subtract(3)); 
box.anchorPane.prefHeightProperty().bind(centerRoomHBox.heightProperty().divide(6/2)); 
            box.setInfo(null, room.getMaxPlayers()); 
          } catch (IOException ex) { 
            bugsnag.notify(ex); 
          } 
       }