3

So I have a Pane with some components in it (Groups and Polygons) and I wanted to make a copy of this Pane, but whenever I do the following it seems like it deletes the children of the original Pane and transfers it to the new one.

Pane pane1 = new Pane();
pane1.getChildren().addAll(poly1, poly2, poly3, group1, group2);
Pane pane2 = new Pane();
pane2.getChildren().addAll(pane1.getChildren());

So my question is, how do you copy these children without removing them from the original Pane?

Karatawi
  • 378
  • 2
  • 6
  • 16
  • I'm not familiar with JavaFx but ... Have you tried to invoke pane1.getChildren().clone()? – RubioRic Mar 20 '16 at 11:10
  • 2
    @RubioRic: `ObservableList` does not extend `Cloneable` and does not provide a public clone method... – fabian Mar 20 '16 at 11:19
  • ObservableList is an interface. It does not implement anything. But what about the underlying implementation that you are using inadvertently. – RubioRic Mar 20 '16 at 12:03
  • 2
    You will have to copy each of your components individually because even cloning a list or other collection will generally not perform a deep copy of its items but this is necessary here because each node may only appear once in an active scene graph. – mipa Mar 20 '16 at 15:04

0 Answers0