Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何访问';网格窗格中有什么?_Java_Loops_Javafx_Fxml_Gridpane - Fatal编程技术网

Java 如何访问';网格窗格中有什么?

Java 如何访问';网格窗格中有什么?,java,loops,javafx,fxml,gridpane,Java,Loops,Javafx,Fxml,Gridpane,我在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.c

我在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>
可能是

假设
gridPane.setGridLinesVisible(false)

但是,当
gridPane.setGridLinesVisible(true)
时,会在gridPane的子列表中添加一个额外的
网格线
(组的类型
)。在这种情况下,您可能需要检查类类型:

for ( Node node : gridPane.getChildren() )
{
    if(node instanceof Label)
        (( Label ) node).setText( "x" );
}

请注意,
gridLinesVisible
属性仅用于调试目的。还有其他选项可以设置网格窗格的样式。

是否可以在不隐藏网格线的情况下进行此操作?您好,我刚刚遇到了这个问题,我不敢相信网格窗格对其线条如此挑剔,谢谢!!!必须回去检查一下:
for ( Node node : gridPane.getChildren() )
{
    (( Label ) node).setText( "x" );
}
for ( Node node : gridPane.getChildren() )
{
    if(node instanceof Label)
        (( Label ) node).setText( "x" );
}