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:
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
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With