Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clone JavaFX Node?

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?

like image 658
Shahmeer Navid Avatar asked Jan 06 '13 07:01

Shahmeer Navid


2 Answers

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.

like image 170
Peter Lamberg Avatar answered Sep 18 '22 15:09

Peter Lamberg


There is no such node duplication function in the JavaFX platform, you will need to write your own which introspects on the properties of the node you are interested in cloning and creates a new node with the required properties.

Using an fxml template for the node definition is probably the easiest way to do this for node's with static initialization properties - but then, as you state in your question, you don't want to use fxml for this, so you'll have to code your cloning logic in Java.

like image 23
jewelsea Avatar answered Sep 17 '22 15:09

jewelsea