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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With