次のように、Java fxml ファイルでグリッド ペインを定義しました。
<GridPane fx:id="grid" gridLinesVisible="true" prefHeight="256" prefWidth="256">
...
<children>
<Label maxHeight="1.8" maxWidth="1.8" />
<Label maxHeight="1.8" maxWidth="1.8" GridPane.columnIndex="1" />
<Label maxHeight="1.8" maxWidth="1.8" GridPane.columnIndex="2" />
<Label maxHeight="1.8" maxWidth="1.8" GridPane.rowIndex="1" />
<Label maxHeight="1.8" maxWidth="1.8" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label maxHeight="1.8" maxWidth="1.8" GridPane.columnIndex="2" GridPane.rowIndex="1" />
<Label maxHeight="1.8" maxWidth="1.8" GridPane.rowIndex="2" />
<Label maxHeight="1.8" maxWidth="1.8" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label maxHeight="1.8" maxWidth="1.8" GridPane.columnIndex="2" GridPane.rowIndex="2" />
</children>
...
</GridPane>
グリッドは 3 x 3 で、各セルにラベルがあります。以下の擬似コードに示すように、グリッドをループして各ラベルのテキストを変更することは可能ですか?
for (cell : grid)
{
cell.label.setText("x");
}