Java Swing保存并加载工作空间/设置

时间:2023-01-24 13:33:09

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:

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

  • Active windows (JFrame) and their sizes and positions on screen
  • 活动窗口(JFrame)及其在屏幕上的大小和位置

  • Table settings, incl selected columns, column order, column width, sorting, filtering
  • 表设置,包括选定的列,列顺序,列宽,排序,过滤

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

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

1 个解决方案

#1


7  

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

#1


7  

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