Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/318.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
在JavaFx中,如何使用网格窗格的坐标从网格窗格中删除特定节点?_Java_Javafx - Fatal编程技术网

在JavaFx中,如何使用网格窗格的坐标从网格窗格中删除特定节点?

在JavaFx中,如何使用网格窗格的坐标从网格窗格中删除特定节点?,java,javafx,Java,Javafx,如果我知道要删除的节点的具体坐标,比如“col:3,row:4”,我如何删除第3列和第4行中的节点? Java中有内置的方法吗?您需要从布局(GridPane)中删除节点(子节点) 公共节点removeNodeByRowColumnIndex(最终整型行、最终整型列、GridPane GridPane){ ObservableList childrens=gridPane.getChildrens(); 用于(节点:子节点){ if(ImageView&&gridPane.getRowIndex

如果我知道要删除的节点的具体坐标,比如“col:3,row:4”,我如何删除第3列和第4行中的节点? Java中有内置的方法吗?

您需要从布局(GridPane)中删除节点(子节点)

公共节点removeNodeByRowColumnIndex(最终整型行、最终整型列、GridPane GridPane){
ObservableList childrens=gridPane.getChildrens();
用于(节点:子节点){
if(ImageView&&gridPane.getRowIndex(节点)=行&&gridPane.getColumnIndex(节点)=列的节点实例){
ImageView=ImageView(节点);//使用要删除的内容
gridPane.getChildren().remove(imageView);
打破
}
} 
}

如果您从上述解决方案中获得空指针异常,请设置要删除的(列,行)节点的父If,您可以这样做

boolean removeFromPane(String id) {
    for (final Node node : this.gridPane.getChildren()) {
        if (node != null 
              && node.getId() != null
              && node.getId().equals(this.selectedTask.toString())) {
            return this.gridPane.getChildren().remove(node);
        }
    }
    return false;
}

没有使用行-列坐标从GridPane中删除子节点的内置方法。相反,您应该使用getChildren()方法返回列表上的索引

因此,您很可能应该制定一个策略,如何将节点添加到GridPane,因为节点只是添加到列表的末尾,而不是按照行或列索引重新排序

此外,请记住,从列表中删除的所有节点都会减少上面所有剩余节点的索引。这也可能是运行时错误的来源

调用静态方法clearConstraints()来移除显式或隐式设置的所有约束可能是值得的


快乐编码。

删除是什么意思?其他节点应该做什么?我的意思是从网格窗格中删除节点。假设我想从网格窗格中删除imageview。其他节点什么都不做。尝试删除Excel中的一个单元格,我会问您其他单元格应该做什么:下面的单元格向上移动,右边的单元格向左移动,或者删除整列或整行……或者您只想将内容分隔开?试试像
imageView.setVisible(false)
首先,我在Excel上做,我在JavaFx上做。其次,我想从gridPane中删除一个元素或节点,我想让它消失。例如,我的网格窗格有不同标签的单元格,如果我单击特定单元格,我希望该单元格上的标签消失。这就是我的意思。它如何回答“我正在尝试删除,比如列:3,行:4”的问题?你的问题是不明确的,你不需要坐标来删除节点,只要你有节点的Fx id,就写gridepane.getChildren()。删除(Fx_id_节点)这不是我的问题。我不认为这是模棱两可的。这是我见过的最奇怪的NPE,我不知道为什么要发短信。。。。
boolean removeFromPane(String id) {
    for (final Node node : this.gridPane.getChildren()) {
        if (node != null 
              && node.getId() != null
              && node.getId().equals(this.selectedTask.toString())) {
            return this.gridPane.getChildren().remove(node);
        }
    }
    return false;
}