Java 设置网格窗格列/行

Java 设置网格窗格列/行,java,javafx-2,fxml,Java,Javafx 2,Fxml,有没有办法设置网格窗格中的列数和行数 我现在有这样的东西: <fx:root type="GridPane" xmlns:fx="http://javafx.com/fxml" stylesheets="view/Style.css" maxHeight="Infinity" maxWidth="Infinity"> <gridLinesVisible>true</gridLinesVisible> <chil

有没有办法设置网格窗格中的列数和行数

我现在有这样的东西:

<fx:root type="GridPane" xmlns:fx="http://javafx.com/fxml"
         stylesheets="view/Style.css"
         maxHeight="Infinity" maxWidth="Infinity">
<gridLinesVisible>true</gridLinesVisible>
    <children>
        <Pane fx:id="center"
              GridPane.columnIndex="1" GridPane.rowIndex="1"
              GridPane.columnSpan="5" GridPane.rowSpan="3"
              GridPane.hgrow="always" GridPane.vgrow="always"/>
        <Pane fx:id="options"
              GridPane.columnIndex="0" GridPane.rowIndex="5"
              GridPane.columnSpan="6"/>
    </children>
</fx:root>

真的
我动态地向其中添加元素


问题是,如果一行/列没有任何元素,它将被擦除,因此窗格的外观很奇怪(比如在(3,0)中添加元素,然后在(2,X)、(1,X)上添加元素,(3,0)上的元素将不会在窗格中居中,因为(4,X)和(5,X)上没有任何元素)

使用adicional HBox和VBox

HBox HB = new HBox();
HB.getChildren().addAll(btnexample1, btnexample2);

GridPane.setHalignment(HB, HPos.LEFT);
HB.setSpacing(5);
grid.add(HB, 0, 8);

你说过当没有元素时就会发生。只要始终有一个元素,但使其具有空白数据。like Label.text=“”

嗯,我不明白如何在我的示例中使用它,例如,如果我想要一个6x5的GridPane,我应该如何使用该代码?(如果可能,请输入使用fxml的id)是否尝试使用?