调整TilePane单元格的大小

时间:2017-06-21 01:53:19

标签: javafx

我绑定Tile Property以使HomeTabCell动态调整其宽度和高度值。但是HomeTabCell的宽度和高度保持不变。

这是一种让它工作的方法,还是我应该使用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);
           }
}

1 个答案:

答案 0 :(得分:0)

我必须从anchorPane HomeTabCell进行public,然后绑定宽度和高度值。

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