"Learning gives Creativity,Creativity leads to Thinking, Thinking provides Knowledge, Knowledge makes you Great"
Wednesday, 13 August 2014
Tuesday, 12 August 2014
Saturday, 26 July 2014
Friday, 25 July 2014
Wednesday, 23 July 2014
Tuesday, 22 July 2014
JavaFX: Removing child from a Group causes Exception
Free
You can't directly modify a List while you're iterating though it. The iterator gets confused.
Do
Do
List<Node> nodesToRemove = new ArrayList<>();
for(Node node : g.getChildren()){
if(node instanceof Text){
nodesToRemove.add(node);
}
}
g.getChildren().removeAll(nodesToRemove);
or (I think):for (Iterator<Node> iterator = g.getChildren().iterator(); iterator.hasNext();) {
if (iterator.next() instanceof Text) {
iterator.remove();
}
}
or, in Java8,g.getChildren().removeAll( g.getChildren().stream()
.filter(node -> node instanceof Text)
.collect(Collectors.toList()));
Subscribe to:
Posts (Atom)