克隆 JavaFX 节点?

Clone JavaFX Node?(克隆 JavaFX 节点?)

本文介绍了克隆 JavaFX 节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

本文标题为:克隆 JavaFX 节点?

基础教程推荐