Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How can I read and save the JavaFX GUI element hierarchy of my program inside a tree (including the main window, Stage, Button, TextBox, etc.)?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
169 views
Welcome To Ask or Share your Answers For Others

1 Answer

There's no automatism for what you want to achieve. The closest thing to loading is to use an fxml. But the problem is the saving. You can't generate an fxml from your scene nodes. Moreover the fxml is dynamic, it doesn't even have a schema.

For the saving you could

  • use JAXB in order to generate a hierarchical XML (i. e. the fxml)
  • implement the JAXB classes of the the node types and with the attributes which you need
  • use an adapter class to simulate e. g. -INF to -Infinity that is required by fxml
  • iterate through all the children in the scene recursively and create the same structure with JAXB classes
  • save to fxml

and for the loading part you can use the standard fxml loader.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...