0
我已經在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×3,並且具有在它的每一個單元的標籤。是否有可能遍歷網格和改變每個標籤中的文本,如下面的僞代碼所示:
for (cell : grid)
{
cell.label.setText("x");
}
這樣做的工作,謝謝! – 5had3sofQu4rtz
是否可以在不隱藏網格線的情況下執行此操作? – 5had3sofQu4rtz
@ 5had3sofQu4rtz請參閱編輯。 –