I am trying to use JFileChooser to only select files eliminating any directories in the folder:
fc.setFileSelectionMode(JFileChooser.FILES_ONLY); // Only look at files
fc.setCurrentDirectory(new File(dbPath));
int returnVal = fc.showOpenDialog(null); // Switch DB dialog
if (returnVal == JFileChooser.APPROVE_OPTION) // Get good DB?
{
filePDF = fc.getSelectedFile().getAbsolutePath(); // Get path
txtTSDir.setText(filePDF);
}
else
However, I am getting both files and directories. This seems pretty straight forward. What have I missed?
Sorry had to rewrite it some times my mind trolls me while explaining.
Okay so you think that setting your FileSelectionMode to FILES_ONLY will make your JFileChooser only display files and wont show directories anymore. But what actually happens is it will no longer let you select a directories as an input. this is to ensure you are getting a file when you expect it to.
BUT. Since it would be discustingly unhandy to navigate without seeing Directories they are still getting displayed and you can go into them(of cause)
Same goes for direcotries_only this will still show you files but you cant select them as input.