I want to dynamically add new rows based on the input number from text field. I have prepared this row (textField and comboBox) in fxml (scene builder) outside of visible scope.
So I have reference to these objects which I want to add:
@FXML
private ComboBox fieldType;
@FXML
private TextField fieldName;
And based on number from other textField I am adding rows to gridPane:
for (int i = 0; i < newRows; i++) {
grid.addRow(grid.impl_getRowCount(), fieldName, fieldType);
}
I get this exception:
Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: Children: duplicate children added: parent = Grid hgap=0.0, vgap=5.0, alignment=TOP_LEFT
I thought that I will clone these objects like this:
public class CloningMachine implements Cloneable {
private Node node;
public CloningMachine() {
}
public CloningMachine setNode(Node node) {
this.node = node;
return this;
}
public Node getNode() {
return node;
}
protected Object clone() throws CloneNotSupportedException {
return super.clone();
}
}
for (int i = 0; i < newRows; i++) {
grid.addRow(grid.impl_getRowCount(), ((CloningMachine)new CloningMachine().setNode(fieldName).clone()).getNode(), ((CloningMachine)new CloningMachine().setNode(fieldType).clone()).getNode());
}
However I get the same exception.
Is it possible to do it somehow? Thanks