I am implementing an Applet which needs to access to file system and I need to show to user mock/fake files under mypc or userhome.
There is a way to do it using JFileChooser with FileSystemView: This is a short example for Windows OS:
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSystemView(new FileSystemView() {
@Override
public File createNewFolder(File containingDir) throws IOException {
//do something, not important here
return null;
}
@Override
public File[] getFiles(File dir, boolean useFileHiding) {
File[] files = super.getFiles(dir, useFileHiding);
// my pc -> desktop -> null
if (dir.getParentFile() == null
|| dir.getParentFile().getParentFile() != null) {
return files;
}
List<File> newFiles = new ArrayList(Arrays.asList(files));
newFiles.add(new File("Custom_File_1"));
newFiles.add(new File("Custom_File_2"));
return newFiles.toArray(new File[newFiles.size()]);
}
});
But the issue is that JFileChooser does not work properly on Mac OS. There is no ability to navigate into any subdirectory, move up from the current directory.
Here is a similar problem:
JFileChooser for directories on the Mac: how to make it not suck? (I switched off DIRECTORIES_ONLY
mode, but it did not help)
Now I am trying to use FileDialog
, but there is another problem:
I can not find a way to show mock/fake files under mypc or userhome (like FileSystemView).
The question is: Is there an ability to fix JFileChooser in MAC OS? Or add mock/fake files into specific directory using FileDialog?