I would suggest using the Preferences class to keep the most recent open items. Thus, if the user restarts the application, the elements will still be available.
Note that on Windows, the Preferences class stores data in the registry, namely, how many native Windows applications store and retrieve recently opened file names.
Also note that the Preferences class simply acts as an API for storing and retrieving (key, value pairs). You still need to decide how you want to store the information, and be responsible for dynamically creating / updating JMenu when accessing the new file. For this, I would suggest implementing Action (extend AbstractAction ) to decide when the user will try to open the file. When Action starts, it must save the newly accessible file name in the Preferences class and dynamically rebuild the JMenu file (in addition to opening the file).
source share