Clone JavaFX Node?

前端 未结 2 833
悲哀的现实
悲哀的现实 2020-12-20 12:27

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

相关标签:
2条回答
  • 2020-12-20 13:01

    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.

    0 讨论(0)
  • 2020-12-20 13:14

    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.

    0 讨论(0)
提交回复
热议问题