Jointts
Jointts

Reputation: 121

JavaFX 8 Duplicate children after getChildren().clear()

Im clearing the Gridpane of all children, then adding children again to the Gridpane yet it says that there are duplicates.

public void render(){
    boardPane.getChildren().clear();
    for(int x = 0; x < xSize; x++){
        for(int y = 0; y < ySize; y++){
            boardPane.add(blockBoard[x][y], x, y);
        }
    }
}

blockBoard[x][y] contains objects that are replaced every render cycle.

Exception in thread "JavaFX Application Thread"    
java.lang.IllegalArgumentException: Children: 
duplicate children added:     parent = Grid hgap=0.0, vgap=0.0,
alignment=TOP_LEFT
at javafx.scene.Parent$2.onProposedChange(Parent.java:454)
at   com.sun.javafx.collections.VetoableListDecorator.add
(VetoableListDecorator.java:206)
at javafx.scene.layout.GridPane.add(GridPane.java:965)
at tetris.Game.render(Game.java:121)

Upvotes: 1

Views: 6805

Answers (1)

user2982622
user2982622

Reputation: 113

that is because of this code from method onProposedChange of Parent Class

childSet.addAll(newNodes);
if (childSet.size() != newLength) {
   throw new IllegalArgumentException(
       constructExceptionMessage(
           "duplicate children added", null));
}

So you just should remove duplicate nodes from blockBoard. Probably you should use TableView for this stuff.

Upvotes: 1

Related Questions