I do not want to specify a directory. I just want it to automatically "know" and open in the directory the user is working in. How do I do this?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
If you want to set the directory they were in at the previous opening of the file chooser you need to set the current directory.
Im not sure if this is what you're looking for, But when they select a file then go to select another file, it will maintain the directory they were in from the previous selection.
If you want your application to look for the user's working directory, you can try this:
Basically, you can't. You need to tell it.
When constructed with a
null
currentDirectory
(such as the default constructor), it will useFileSystemView#getDefaultDirectory
.You could create a single instance of
JFileChooser
for each base task (one for saving, one for opening for example) and simply maintain that instance, which will "remember" the last directory that it was using, you'd still need to seed it with a starting directory thoughAnother choice would be to construct some kind of library call that could load and save the last directory the user used based on some unique key. This means you could simply do something like...
Which would load the last known directory for the supplied key and show the
JFileChooser
configured with that value and would be capable of returning the selectedFile
ornull
if the user canceled the operation...for example...This examples defaults to the
user.dir
on first showing. It then retains the instance of the chooser to automatically track the last load or save location, as suggested by MadProgrammer.