Serialize JavaFX components

You are correct, JavaFX (as of 2.1) does not support serialization of components using the Java Serializable interface – so you cannot use that mechanism.

JavaFX can deserialize from an FXML document using the FXMLLoader.load() method.

The trick though, is how to write your existing components and states out to FXML?

Currently, there is nothing public from the platform which performs FXML serialization. Apparently, creating a generic scenegraph => FXML serializer is quite a complex task (and there is no public 3rd party API for this that I know of). It wouldn’t be too difficult to iterate over the scenegraph and write out FXML for a limited set of components and attributes.

Leave a Comment