Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.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
如何通过单击“在GridPane(Javafx)中自动添加上面的行”;加上「;按钮_Javafx - Fatal编程技术网

如何通过单击“在GridPane(Javafx)中自动添加上面的行”;加上「;按钮

如何通过单击“在GridPane(Javafx)中自动添加上面的行”;加上「;按钮,javafx,Javafx,我想在GridPane上面添加索引为0的一行,问题是当我在GridPaneMyGrid.add(Label,0,0)中添加一个元素时,此标签将与放置位置(0,0)中的上一个标签重叠 我的FXML网格 控制器中的代码 private Label AnneeInfo = new Label("année"); private TextField AnneeEffectif = new TextField(); //Action in button AnneeEffect

我想在GridPane上面添加索引为0的一行,问题是当我在GridPane
MyGrid.add(Label,0,0)
中添加一个元素时,此标签将与放置位置(0,0)中的上一个标签重叠

我的FXML网格


控制器中的代码

private Label AnneeInfo = new Label("année");
private TextField AnneeEffectif = new TextField();



//Action in button
AnneeEffectif.setLayoutX(60);
CalenderGrid.add(AnneeInfo, 0, 0);
CalenderGrid.add(AnneeEffectif, 1, 0);

您必须增加以前在
网格窗格
中每个子级的行索引,例如:

//Action in button
AnneeEffectif.setLayoutX(60);

// add constraint for new row
List<RowConstraints> constraints = CalenderGrid.getRowConstraints();
constraints.add(constraints.get(0));

// move all children down one row
insertRows(1);

CalenderGrid.addRow(0, AnneeInfo, AnneeEffectif);
注意:如果要多次添加行,则在字段中存储新的
节点
s而不在按钮的操作处理程序中创建它们似乎是错误的,因为不能在场景中多次使用
节点
s

private void insertRows(int count) {
    for (Node child : CalenderGrid.getChildren()) {
        Integer rowIndex = GridPane.getRowIndex(child);
        GridPane.setRowIndex(child, rowIndex == null ? count : count + rowIndex);
    }
}