1

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?

Community
  • 1
  • 1
rgolovakha
  • 518
  • 2
  • 5
  • 17
  • Without showing us your code, it is unlikely that we can help you. – Sentry Dec 19 '14 at 19:24
  • 1
    Sorry if something is not clear. Appreciate your note. I added some code snippet. Please let me know if I need to provide any more details. – rgolovakha Dec 20 '14 at 14:00
  • 1
    Okay, to be honest, I hardly understand your problem. It seems like you're having two problems: 1) You can't switch directories in MacOS. 2) You can't display fake/mock files. Am I right? If so, please split this into two questions, because most people here are probably as confused as I am. – Sentry Dec 22 '14 at 16:46
  • 1
    Thanks again for your note that my question is not clear. I edited it again. In general I have one issue and I am trying to fix it using two ways: JFileChooser or FileDialog. But both are unsuccessful now. – rgolovakha Dec 23 '14 at 11:20
  • Okay, it seems clear to me now. Unfortunately, I don't own a Mac, so you have to hope for another user here to help you :( – Sentry Dec 23 '14 at 15:05

0 Answers0