Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Swing save and load workspace/settings

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:

  • Active windows (JFrame) and their sizes and positions on screen
  • 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

like image 736
hgus1294 Avatar asked Feb 28 '12 10:02

hgus1294


People also ask

Where are the properties of a Swing application stored?

Sample Swing application On startup, the program will try to load properties from config.properties file. If the file has not existed before, it will use the default properties. When clicking on the Save button, the properties values will be stored in the config.properties file.

How do I Save properties in a file in Java?

Saving properties file To save the properties into the file permanently, use the store () method for plain text file and storeToXML () method for XML file. And we have to supply either a java.io.Writer object or an OutputStream object to these methods and also a comment text.

What information is saved within workspaces?

When you save a workspace, all open NinjaTrader windows as well as their size, location and screen position are stored. The following items are also saved within workspaces: The custom NinjaTrader workspace seen above includes several market analysis and order entry features arranged in a personalized way.

What is JTable in Java Swing?

Java Swing | JTable. The JTable class is a part of Java Swing Package and is generally used to display or edit two-dimensional data that is having both rows and columns. It is similar to a spreadsheet.


1 Answers

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.

like image 138
trashgod Avatar answered Oct 25 '22 15:10

trashgod