问题描述
我在 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 节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!