Please, can anyone help me to undersatand how I can save selected files history in JFileChooser and show it in the field where locates file name using comboBox. Thanks.
Asked
Active
Viewed 190 times
0
-
`JFileChooser` provides the ability to supply an "accessory" view which you could use to list the recently opened files or provide a means for people to access that information. Start by having a look at [How to use file chooser](https://docs.oracle.com/javase/tutorial/uiswing/components/filechooser.html) for more details – MadProgrammer Oct 11 '17 at 09:37
-
@MadProgrammer, thanks, but I need to show it in the component where is last selected file, but there are must be more that one file. I don't need to create helping components. – Oct 11 '17 at 09:52
-
1Okay, so when the "okay" action is triggered on the `JFileChooser` maintain a reference to the last file/folder and if required, store in the system configuration. The `Preferences` API would probably be the simplest solution – MadProgrammer Oct 11 '17 at 12:04
-
@MadProgrammer, yes. It helped. Thank you very much! It works as I want - thru whole system. – Oct 13 '17 at 10:01
1 Answers
0
Swing JFileChooser has an method to set the initial directory when your button is pressed using method setCurrentDirectory(File dir)
You can always retrieve your last file accessed location using getCurrentDirectory(). You can then save it in some variable or in some configuration file and then retrieve it when the file chooser is enabled...
See also Is there any way to make java file selection dialogs remember the last directory? for more information

MaVRoSCy
- 17,747
- 15
- 82
- 125