Java Swing保存并加载工作空间/设置 [英] Java Swing save and load workspace/settings

查看:131
本文介绍了Java Swing保存并加载工作空间/设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java Swing应用程序,它包含一堆帧,而这些帧主要包含显示大量数据的表。由于在启动时安排所有窗口和表格总是麻烦且耗时,我想实现工作区功能,以便用户可以保存首选项设置,并在启动时选择自动加载存储的工作区让所有窗口和表格显示为先前保存的。具体来说,我希望存储在工作区中的设置是:

I have a Java Swing application that contains a bunch of frames which in turn predominantly contains tables that display large amounts of data. Since it is always a hassle and its time consuming to arrange all windows and tables on startup, I would like to implement 'workspace'-functionality so that the user can save a setup of preference and on startup choose to automatically load the stored workspace to have all windows and tables appear as previously saved. Specifically, the settings that I wish to store in a workspace are:


  • 活动窗口(JFrame)及其在屏幕上的大小和位置

  • 表设置,包括选定列,列顺序,列宽,排序,过滤

有没有人知道一个聪明而简单的方法来实现这一点,没有明显的,并且看起来是一个非常复杂和繁琐的解决方案,迭代所有打开的窗口并使用首选项 api?谢谢

Does anyone know of a smart and easy way to accomplish this without the obvious, and what seems like a very complex and cumbersome, solution of iterating over all open windows and saving each piece of information with the Preferences api? Thanks

推荐答案

在这种情况下,显而易见的解决方案, java.util.prefs.Preferences ,可能是正确的。来自此游戏 RCPrefs 是一个演示保存的简单示例各种数据类型,包括枚举。确切的实现高度依赖于应用程序。虽然单调乏味,但它并不是特别复杂。为方便起见,示例使用静态方法;框架和表格首选项可能每个都值得上课。

In this case, the obvious solution, java.util.prefs.Preferences, is probably the correct one. RCPrefs from this game is a simple example that demonstrates saving a variety of data types, including enum. The exact implementation is highly dependent on the application. While tedious, it needn't be especially complex. For expedience, the example uses static methods; frame and table preferences are probably worth a class each.

这篇关于Java Swing保存并加载工作空间/设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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