I have a problem with java swing where the user must select a folder, so I use the code below.
JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if(fc.showDialog(singleton, SELECT) == JFileChooser.APPROVE_OPTION) {
File folder = fc.getSelectedFile();
String path = folder.getPath() + File.separatorChar + MYAPPFOLDER;
}
Now there are two ways that a user can select a folder
- Go to the folder and select the folder
- Go to the folder, go to the folder and click
Both methods work fine on windows, but on OS X I get
If I do 1: path = Users/<username>/Desktop/MYAPPFOLDER
If I do 2: path = Users/<username>/Desktop/Desktop/MYAPPFOLDER
How to avoid this second case?
Thanks in advance.
source
share