FileDialog模拟文件

时间:2014-12-19 18:23:13

标签: java macos jfilechooser

我正在实现一个需要访问文件系统的Ap​​plet,我需要在mypc或userhome下向用户显示模拟/假文件。

有一种方法可以使用FileFystemView使用JFileChooser: 这是Windows操作系统的一个简短示例:

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()]);
    }
});

但问题是JFileChooser在Mac OS上无法正常运行。无法导航到任何子目录,从当前目录向上移动。 这是一个类似的问题: JFileChooser for directories on the Mac: how to make it not suck?(我关闭了DIRECTORIES_ONLY模式,但没有帮助)

现在我正在尝试使用FileDialog,但还有另一个问题: 我无法找到在mypc或userhome下显示mock / fake文件的方法(如FileSystemView)。

问题是:是否有能力在MAC OS中修复JFileChooser?或者使用FileDialog?

将mock / fake文件添加到特定目录中

0 个答案:

没有答案