2

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

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

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:

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

1
  • 1
    There's no built-in way to do this. You need to persist the state of the application (the state you are interested in) when it closes (you can override Application.stop() to execute code when the application shuts down); then in your controller's initialize() method read the last state and apply it to the application that is starting up. Commented Jan 11, 2015 at 2:32

1 Answer 1

2

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

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

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.

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.