JFileChooser returns incorrect path in OS X (folders only mode)
Posted
by Virat Kadaru
on Stack Overflow
See other posts from Stack Overflow
or by Virat Kadaru
Published on 2010-06-17T16:59:26Z
Indexed on
2010/06/17
17:03 UTC
Read the original article
Hit count: 180
I have a problem in java swing where the user has to select a folder, so I am using 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 2 ways a user may select the folder
- Navigate to the folder and select the folder
- Navigate to the folder, go into the folder, and click select
Both ways 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 do I avoid this 2nd case?
Thanks in advance.
© Stack Overflow or respective owner