JavaFX read and save GUI elements

与世无争的帅哥 提交于 2019-12-13 08:28:31

问题


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.)?


回答1:


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.



来源:https://stackoverflow.com/questions/35415240/javafx-read-and-save-gui-elements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!