JavaFX读取并保存GUI元素 [英] JavaFX read and save GUI elements

查看:344
本文介绍了JavaFX读取并保存GUI元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在树中读取和保存程序的JavaFX GUI元素层次结构(包括主窗口, Stage Button TextBox 等)?

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

推荐答案

对于你想要达到的目标,没有自动化。最接近加载的是使用fxml。但问题是节省。您无法从场景节点生成fxml。此外,fxml是动态的,它甚至没有架构。

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.

对于保存你可以


  • 使用JAXB生成分层XML(即fxml)

  • 实现节点类型的JAXB类以及您需要的属性

  • 使用适配器类来模拟e。 G。 -inF到-ffml所需的-Infinity

  • 以递归方式遍历场景中的所有子节点并使用JAXB类创建相同的结构

  • save到fxml

  • 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

对于加载部分,你可以使用标准的fxml加载器。

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

这篇关于JavaFX读取并保存GUI元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆