5

I know that I can load an FXML file into a Parent object with the following:

    parent = FXMLLoader.load(getClass().getResource(fxmlFile.getAbsolutePath()));

Now I want to do the exact opposite and save a Parent object as the root of an FXML file.

Does anyone know how to accomplish this?

Ben Trengrove
  • 8,191
  • 3
  • 40
  • 58
CBK
  • 141
  • 1
  • 6

1 Answers1

2

There is currently no public API which allows the serialization of a generic JavaFX object into FXML. It is also far from trivial to implement such a thing, because it is not known at runtime which values should be initialized where and so on.

The JavaFX SceneBuilder uses a mechanism to serialize to FXML to implement drag & drop functionality, but the code for this is quite heavy.

See:
https://forums.oracle.com/forums/thread.jspa?messageID=10377102

zhujik
  • 6,514
  • 2
  • 36
  • 43