JFileChooser:选择模式为文件和目录时,无法选择桌面 [英] JFileChooser: Cannot select Desktop when Selection Mode is File and Directories

查看:82
本文介绍了JFileChooser:选择模式为文件和目录时,无法选择桌面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了JFileChooser的问题,想看看是否有解决方法.

I ran into an issue with JFileChooser and wanted to see if there is a workaround.

如果创建了JFileChooser且setFileSelectionMode为FILES_AND_DIRECTORIES,则当用户单击左侧(在XP中)的快捷按钮(在XP中)如桌面"或我的文档"或下拉至桌面时,该字段不会放置在文件名JTextPane中.而且,当单击选择/接受"按钮时,什么也不会发生(因为isDirectorySelected()由于某种原因返回了false).

If the JFileChooser is created and the setFileSelectionMode is FILES_AND_DIRECTORIES, when a user clicks a shortcut button on the left (in XP) such as Desktop or My Documents or drop down to Desktop, the field is not placed in the File Name JTextPane. And when clicking the "Select/Accept" button, nothing happens (because isDirectorySelected() returns false for some reason).

覆盖approveSeletion无效,因为BasicFileChooser中的事件处理程序函数未调用它.

Overriding the approveSeletion does not work because the Event Handler function in BasicFileChooser does not call it.

我应该如何选择桌面,而无需手动导航到该桌面,而是单击左侧的快捷方式?

How would I make it so the Desktop can be selected without having to navigate to it manually, but by clicking the shortcut on the left?

谢谢

推荐答案

在Windows中,桌面不受文件系统中任何文件的支持-它是一个外壳命名空间.因此,JFileChooser 确实没有什么可以退还给您的.是的,我知道这里有一个包含用户桌面的文件夹-但请记住,桌面实际上显示为用户桌面和所有用户"桌面文件夹的组合-加上外壳程序添加但不包含的其他内容任何文件夹(如垃圾桶)的位置.因此,返回代表桌面"的File对象几乎是不可能的.

In Windows, the desktop is not backed by any file in the file system - it's a shell namespace. So there really isn't anything that JFileChooser could return to you. Yes, I know that there is a folder that contains the desktop for the user - but remember that the desktop actually displays as a composite of the user's desktop and the All Users desktop folder - plus other things that are added by the shell but not part of any folder (like the trash bin). So returning a File object that represents the 'desktop' is pretty much a non-starter.

长短:问问自己为什么需要这样做-很有可能您将深入了解本机代码领域,处理名称空间PIDL和各种您可能不想涉及的琐事(对于我的生活,我不明白为什么M $必须使这种东西变得如此难以使用)...

Long and short: Ask yourself why you need to do this - chances are that you are going to wind up deep into native code territory, dealing with namespace PIDLs and all sorts of nastiness that you may not want to get into (for the life of me, I cannot understand why M$ had to make this stuff so amazingly difficult to use)...

这是Windows Shell名称空间的简介,因此您可以了解其中涉及的内容:

Here's an intro to Windows shell namespaces so you'll have a feel for what's involved:

http://msdn.microsoft. com/en-us/library/cc144090%28v = vs.85%29.aspx

这篇关于JFileChooser:选择模式为文件和目录时,无法选择桌面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆