有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java文件对话框模拟文件

我正在实现一个小程序,它需要访问文件系统,我需要向用户显示mypc或userhome下的模拟/伪造文件

有一种方法可以在FileSystemView中使用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(如FileSystemView)下显示模拟/假文件的方法

问题是:有没有能力修复MAC OS中的JFileChooser?或者使用FileDialog将模拟/假文件添加到特定目录中


共 (0) 个答案