問題描述
我在 JavaFX 場景構建器中創建了一個 Node
(AnchorPane
) 并且想知道如何克隆它.
I have created a Node
(AnchorPane
) in the JavaFX scene builder and was wondering how to clone it.
我在 JavaFX 2.0 中看到 復制/克隆節點,但我需要克隆 Node
而無需重新加載 fxml.
I saw Duplicate/Clone Node in JavaFX 2.0 but I need to clone the Node
without re-loading the fxml.
有沒有辦法在 JavaFX 2 中實現這一點?
Is there any way to achieve this in JavaFX 2?
推薦答案
可以將需要復制的組件放在單獨的.fxml
文件中.
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.
此外,您可以將 <fx:include source=".??.."/>
元素編輯到主 .fxml
文件并包含單獨的 .fxml
文件.然后,您仍然可以在 JavaFX Builder 中使用它.
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.
這篇關于克隆 JavaFX 節點?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!