Is it possible to change order of Nodes in JavaFX2 children list? I tried set()
and Collections.swap()
however both throw IllegalArgumentException
in Parent
as in some point the children list contains the same item at two positions (when node is at new position and has not been removed from the old position). There are flags inside Parent which JavaFX uses internaly in toFront()
and toBack()
which prevents the exception, however there is no way to access them from outside.
java.lang.IllegalArgumentException: Children: duplicate children added: parent = HBox@1424bf0
at javafx.scene.Parent$1.onProposedChange(Parent.java:307)
at com.sun.javafx.collections.VetoableObservableList.set(VetoableObservableList.java:156)
at com.sun.javafx.collections.ObservableListWrapper.set(ObservableListWrapper.java:281)
at java.util.Collections.swap(Collections.java:532)
You can move the child in the parent's children list by
Refer to this code: