开发者

JFileChooser - Starting at the 'Computer' e.g. C: D: E: drives

I'm trying to add the finishing touches to an application I've been developing and I'd really like it so my fileChooser sets the current directory as the area in which you can select which drive to 开发者_JAVA百科start from. I've looked at the Windows 7 path for this area and it seems to just be called 'Computer'. I've tried entering this into the space where "C:\" is in the below code but that doesn't work.

fileChooser.setCurrentDirectory(new java.io.File("C:\\"));

Does anyone know what you would enter to have it so the user first selects which drive to open from?


Well, the problem is that what is called "Computer" in Windows, is not really a folder, just behaves like one. It's just a special way Windows use to display the most common folders (like C:, D:, Documents etc.), just to make the user's life easier. I'm not sure how you can achieve what you want, but i think this might help you: link


This worked for me under Windows XP:

     file_open_dialog = new JFileChooser();
     try {
        File dummy_file = new File(new File("C:\\").getCanonicalPath());
        file_open_dialog.setCurrentDirectory(dummy_file);
        file_open_dialog.changeToParentDirectory();
     } catch (IOException system_event) {
        ;
     };


Not sure what you need to put. But if you can browse in the file chooser to the location you want, select a file and in Java printout the path. That should give you want you need to know.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜