- The buttons need to be in a grid like in the second picture
- The buttons need to be square
- The buttons need to resize to fit into the window
Я попробовал привязать ширину pref кнопок с их высотой. Я также пытался изменить ширину ряда сетки. Все это заканчивается неожиданным поведением, когда кнопки не остаются как сетка при изменении размера. Мой код следует.private GridPane drawBlock(Block block) {
GridPane gridPane = new GridPane();
gridPane.getStyleClass().add("board-block");
DoubleProperty doubleProperty = new SimpleDoubleProperty();
for (int i = 0; i < block.getRowsList().size(); i++) {
for (int j = 0; j < block.getRowsList().get(i).getBoxes().size(); j++) {
StateButton stateButton = new StateButton();
stateButton.setBox(block.getRowsList().get(i).getBoxes().get(j));
stateButton.setOnAction(e -> stateButton.updateState());
stateButton.textProperty().bind(stateButton.getBox().stateIconProperty());
// stateButton.maxHeightProperty().bind(stateButton.widthProperty());
stateButton.prefHeightProperty().bind(stateButton.widthProperty());
// stateButton.minHeightProperty().bind(stateButton.widthProperty());
stateButton.getBox().setState(Box.BoxState.UNSURE);
stateButton.getBox().update();
if (i+j==0) doubleProperty.bind(stateButton.widthProperty());
}
}
RowConstraints rowConstraints = new RowConstraints();
rowConstraints.prefHeightProperty().bind(doubleProperty);
gridPane.getRowConstraints().add(rowConstraints);
return gridPane;
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... each-other