"Learning gives Creativity,Creativity leads to Thinking, Thinking provides Knowledge, Knowledge makes you Great"
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()));
Wednesday, 16 July 2014
JavaFx Group
@DefaultProperty(value="children")
public class Group
extends Parent
- A
Groupnode contains an ObservableList of children that are rendered in order whenever this node is rendered. AGroupwill take on the collective bounds of its children and is not directly resizable.
- Any transform, effect, or state applied to a
Groupwill be applied to all children of that group. Such transforms and effects will NOT be included in this Group's layout bounds, however if transforms and effects are set directly on children of this Group, those will be included in this Group's layout bounds.
- By default, a
Groupwill "auto-size" its managed resizable children to their preferred sizes during the layout pass to ensure that Regions and Controls are sized properly as their state changes. If an application needs to disable this auto-sizing behavior, then it should setautoSizeChildrentofalseand understand that if the preferred size of the children change, they will not automatically resize (so buyer beware!).
- Group Example:
import javafx.scene.*;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
import java.lang.Math;
Group g = new Group();
for (int i = 0; i < 5; i++) {
Rectangle r = new Rectangle();
r.setY(i * 20);
r.setWidth(100);
r.setHeight(10);
r.setFill(Color.RED);
g.getChildren().add(r);
}
Subscribe to:
Comments (Atom)



