Я пытаюсь поместить изображение на кнопку, когда пользователь нажимает эту кнопку. Кнопки расположены в виде сетки с похожими типами кнопок. Проблема в том, что размер кнопки изменяется, я не знаю почему.
Это часть моего контроллера. java
//box row where button is clicked
int row = GridPane.getRowIndex((Node) actionEvent.getSource());
//box column where button is clicked
int column = GridPane.getColumnIndex((Node) actionEvent.getSource());
if (grid.markGrid(row, column, playerPlaying))
{
//set mark on the Button
Image mark;
if (playerPlaying == Player.PLAYER1)
mark = new Image(getClass().getResourceAsStream("x.png"));
else
mark = new Image(getClass().getResourceAsStream("circle.png"));
Button buttonClicked = (Button) actionEvent.getSource();
ImageView imageView = new ImageView(mark);
imageView.setFitHeight(buttonClicked.getHeight());
imageView.setFitWidth(buttonClicked.getWidth());
buttonClicked.setGraphic(imageView);
Это часть моего файла f xml
<GridPane fx:id="buttonsGrid">
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS"/>
<ColumnConstraints hgrow="ALWAYS"/>
<ColumnConstraints hgrow="ALWAYS
</columnConstraints>
<rowConstraints>
<RowConstraints vgrow="ALWAYS"/>
<RowConstraints vgrow="ALWAYS"/>
<RowConstraints vgrow="ALWAYS"/>
</rowConstraints>
<Button mnemonicParsing="false" GridPane.rowIndex="0" GridPane.columnIndex="0" styleClass="grid-button"
prefWidth="150" prefHeight="150" maxHeight="Infinity" maxWidth="Infinity"
onAction="#gridClick" GridPane.valignment="CENTER" GridPane.halignment="CENTER"/>
<Button mnemonicParsing="false" GridPane.rowIndex="0" GridPane.columnIndex="1" styleClass="grid-button"
prefWidth="150" prefHeight="150" maxHeight="Infinity" maxWidth="Infinity"
onAction="#gridClick" GridPane.valignment="CENTER" GridPane.halignment="CENTER"/>
<Button mnemonicParsing="false" GridPane.rowIndex="0" GridPane.columnIndex="2" styleClass="grid-button"
prefWidth="150" prefHeight="150" maxHeight="Infinity" maxWidth="Infinity"
onAction="#gridClick" GridPane.valignment="CENTER" GridPane.halignment="CENTER"/>
<Button mnemonicParsing="false" GridPane.rowIndex="1" GridPane.columnIndex="0" styleClass="grid-button"
prefWidth="150" prefHeight="150" maxHeight="Infinity" maxWidth="Infinity"
onAction="#gridClick" GridPane.valignment="CENTER" GridPane.halignment="CENTER"/>
<Button mnemonicParsing="false" GridPane.rowIndex="1" GridPane.columnIndex="1" styleClass="grid-button"
prefWidth="150" prefHeight="150" maxHeight="Infinity" maxWidth="Infinity"
onAction="#gridClick" GridPane.valignment="CENTER" GridPane.halignment="CENTER"/>
<Button mnemonicParsing="false" GridPane.rowIndex="1" GridPane.columnIndex="2" styleClass="grid-button"
prefWidth="150" prefHeight="150" maxHeight="Infinity" maxWidth="Infinity"
onAction="#gridClick" GridPane.valignment="CENTER" GridPane.halignment="CENTER"/>
<Button mnemonicParsing="false" GridPane.rowIndex="2" GridPane.columnIndex="0" styleClass="grid-button"
prefWidth="150" prefHeight="150" maxHeight="Infinity" maxWidth="Infinity"
onAction="#gridClick" GridPane.valignment="CENTER" GridPane.halignment="CENTER"/>
<Button mnemonicParsing="false" GridPane.rowIndex="2" GridPane.columnIndex="1" styleClass="grid-button"
prefWidth="150" prefHeight="150" maxHeight="Infinity" maxWidth="Infinity"
onAction="#gridClick" GridPane.valignment="CENTER" GridPane.halignment="CENTER"/>
<Button mnemonicParsing="false" GridPane.rowIndex="2" GridPane.columnIndex="2" styleClass="grid-button"
prefWidth="150" prefHeight="150" maxHeight="Infinity" maxWidth="Infinity"
onAction="#gridClick" GridPane.valignment="CENTER" GridPane.halignment="CENTER"/>
</GridPane>
Вот изображение измененной сетки