Clone JavaFX Node?

Shahmeer Navid picture Shahmeer Navid · Jan 6, 2013 · Viewed 11.9k times · Source

I have created a Node (AnchorPane) in the JavaFX scene builder and was wondering how to clone it.

I saw Duplicate/Clone Node in JavaFX 2.0 but I need to clone the Node without re-loading the fxml.

Is there any way to achieve this in JavaFX 2?

Answer

Peter Lamberg picture Peter Lamberg · Oct 22, 2015

You can place the component that needs to be duplicated in a separate .fxml file.

Then you can load the separate file as many times as needed adding the nodes to the appropriate root in the main scene.

Additionally you can edit an <fx:include source="..."/> element to the main .fxml file and include the separate .fxml file. You can then still work with it in the JavaFX Builder.