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 ?)
As to your first question, check the link in my comments
As to the second, I would suggest that it comes down to which libraries they are linking to in order to facility the functionality. Just because the OS has updated doesn't mean that the old libraries have been removed. In order to maintain compatibility with older versions of applications, these libraries are normally maintained for some time.
You could take a look at xFileDialog (via this post Alternative to JFileChooser)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With