将JavaFX场景保存到FXML文件中 [英] Save JavaFX scene into FXML file
问题描述
任何人都知道如何将JavaFX场景保存到JavaFX FXMLLoader可以加载的FXML文件中吗?
Anyone knows how to save a JavaFX scene into FXML file that can be loaded by the JavaFX FXMLLoader?
SceneBuilder允许执行此操作,但是如果我手动构建场景,如何将其保存到FXML文件中?
The SceneBuilder allows to do it, but if I build the scene manually, how I can save it into FXML file?
推荐答案
没有这样的库AFAIK,我不确定是否可以创建一个通用库.在简单的情况下可能是有可能的,但是我想即使如此,它仍然需要很多工作.
There is no such library, AFAIK, and I'm not sure if it's possible to create a generic one. It might be possible for simple cases, but even then it's a lot of work, I guess.
Here is the FXML format explained, if you want to give it a try: http://docs.oracle.com/javase/8/javafx/api/javafx/fxml/doc-files/introduction_to_fxml.html
您可以遍历场景图/节点并生成FXML文件.
You could traverse your scene graph/ node and generate an FXML file.
但是为什么需要FXML格式?仅用FXML重写布局而不是像这样编写库可能会更容易.
But why do you need the FXML format? It might be easier just to rewrite the layout in FXML instead of writing a library like this.
如果您设法编写了这样的库,请告诉我们! :-)
If you manage to write such a library - let us know! :-)
这篇关于将JavaFX场景保存到FXML文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!