将用户界面保存到fxml:javafx [英] Saving user interface into fxml : javafx

查看:198
本文介绍了将用户界面保存到fxml:javafx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个javafx应用程序,让用户可以添加他/她想要的按钮。

I have an javafx application which let's the user to add as much as buttons he/she wants.

我加载主场景根来自 fxml 文件,其中包含默认的用户界面

I load my main scene root from an fxml file which contains the default user-interface.

当用户更改界面时,我使用 @FXML 注释更改场景。

As the user changes the interface, I change the scene using @FXML annotation.

此更改是临时的,用户界面将与下次应用程序运行时的用户界面相同。所以这是我的问题:

This changes are temporary and the user interface will be same as what it was, in the next time application run. So here's my question:

如何在运行时将对应用程序界面所做的更改保存到新的 fxml file?

How can I save the changes made to interface of the application during runtime to a new fxml file?

推荐答案

FXML文件是一个xml文件,因此您可以使用任何XML Libary进行写入。

A FXML File is a xml File so you can Write with Any XML Libary.

但我建议将按钮保存在json或属性文件中,然后将它们添加回代码。

But i would recommend to save the Buttons in a json or properties file, and add them back over Code.

因此,如果应用程序停止将按钮保存到文件中,并且如果应用程序再次启动将它们添加到场景中,则将它们保存到FXML文件中会更容易。

So if the Applications stops save the Buttons to the File and if the Applications starts again add them to the Scene, this is much easier as saving them into an FXML File.

但如果你真的想用FXML做这个,请看看
https:// bitbucket.org/gluon-oss/scenebuilder
也许您可以使用SceneBuilder中的一些代码将场景保存为FXML。

But if you realy want to do this with FXML take a look at https://bitbucket.org/gluon-oss/scenebuilder maybe you can use some of the Code from the SceneBuilder to save your scene as an FXML.

这篇关于将用户界面保存到fxml:javafx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆