【发布时间】:2020-08-20 19:09:16
【问题描述】:
我有一个按钮网格。当我单击一个按钮时,一个 ImageView 被插入其中,并且由于某种原因,单元格高度增加了。我不明白为什么以及如何解决它。如何使单元格大小保持不变?
按钮点击后第一行高度增加。
我的控制器类:
public class Controller {
public GridPane gameTable;
public Label score1;
public Label score2;
Image openImage = new Image(getClass().getResourceAsStream("/open.jpg"));
MyButton open1;
MyButton open2;
Player player1 = new Player();
Player player2 = new Player();
Player currentPlayer = player1;
public void initialize(){
System.out.println(gameTable.getRowCount()+" "+gameTable.getColumnCount());
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 5; j++) {
MyButton btn = new MyButton(i);
btn.setMaxWidth(Double.MAX_VALUE);
btn.setMaxHeight(100);
gameTable.add(btn, i, j);
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
ImageView iv = new ImageView(openImage);
iv.setPreserveRatio(true);
iv.setFitWidth(btn.getWidth()-10);
btn.setGraphic(iv);
}
});
}
}
}
}
【问题讨论】:
标签: button javafx imageview gridpane