首页 > 解决方案 > 重新插入节点 JavaFX 时出现 ConcurrentModificationException

问题描述

我对这段代码有疑问:

for(Node n : start.getChildren()) {
                    singlewidth = ((CustomController) n).getWidth();
                    totalwidth += singlewidth;
                if(swidth < totalwidth) {
                    //start.getChildren().remove(b);
                    start.getChildren().add(mb);
                    start.getChildren().remove(n);
                }
                if(swidth > totalwidth){
                    start.getChildren().add(n);
                    start.getChildren().remove(mb);
                }
            }

这里的诀窍是我想遍历 HBox 中的所有元素,并尝试按宽度调整它们。但是在我重新添加节点 n 的地方,NetBeans 抛出了 ConcurrentModificationException。有人可以帮我吗?

标签: javafx

解决方案


推荐阅读