I'm trying to use FileDialog instead of JFileChooser to get more natural behaviour on OSX, especially important is the Favourites column with clear links to shared folders that are hidden under /Volumes using JFileChooser.
I'm using Java 7, and for that reason I'm not using Quaqua JFileChooser as it hasnt been updated for a year and Im unsure if it compatible with Oracles Java 7.
But Im hitting a problem, is there a way to get FileDialog to only allow a folder to be opened rather than a file, I set a filename filter but it seemed to have no effect and there is no
.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
like there is for JFileChooser.
public void actionPerformed(ActionEvent e)
{
FileDialog chooser = new FileDialog(SongKong.mainWindow.frame);
chooser.setFilenameFilter(new FolderFilter());
chooser.setMode(FileDialog.LOAD);
chooser.setVisible(true);
String folderSelected = chooser.getDirectory();
File folder = new File(folderSelected) ;
if(folder.exists() && folder.isDirectory())
{
//Do something with selected folder
}
}
class FolderFilter implements FilenameFilter
{
public boolean accept(File dir, String name)
{
return new File(dir,name).isDirectory();
}
}
(As an aside tried the code on WIndows 7 as well but still looks like Windopws XP dialog even though meant to be a native dialog, how come ?)