我请求对当前使用 JFileChooser 的小小程序进行一些更改。
主要的抱怨之一是文件选择器使用起来很痛苦,因为它的行为与本机小部件不同,尤其是导航到根级别时。
因此,知道这一点以及 JFileChooser 遇到的所有其他问题(例如 Windows 上的 zip 文件缓存......),我想知道 Java 世界中是否存在可行的替代方案。
当然,有使用本机小部件的 SWT,但将小程序大小增加 25 并不是一个真正的选择。 那么,有没有更好的纯java实现文件选择器呢?
I've a request to make some changes to a little applet that currently use a JFileChooser.
One of the main complaints is that the file chooser is a pain in the ass to use because it behaves differently than the native widget, especially for navigating up to the root level.
So, knowing that and all the other issue JFileChooser suffer (like the zip file caching on windows...), I was wondering that a viable alternative exists in the java world.
Of course, there is SWT that use the native widget, but increasing the applet size by 25 is not really an option. So, is there a better pure java implementation of a file chooser?
发布评论
评论(5)
AWT
FileDialog
实际上确实使用了本机组件,但与大多数 AWT 与 Swing 问题一样,它的灵活性和可定制性比 Swing 的
JFileChooser
低得多。 因此需要权衡:JFileChooser
可能有一个笨重的用户界面,但它通常更适合大多数用途。 不过,如果您确实希望文件选择对话框的外观和感觉像本机对话框一样,那么您可以使用FileDialog
。The AWT
FileDialog
actually does use the native component, but as with most AWT vs. Swing issues, it's much less flexible and customizable than Swing'sJFileChooser
. So there's a tradeoff:JFileChooser
may have a clunky user interface, but it's usually better for most purposes. If you really want your file choosing dialogs to look and feel like the native ones, though, then you can go withFileDialog
.我知道这有点晚了,但它可能会帮助其他用户。 您可以将应用程序的 UI 自定义为操作系统的 UI:
I know this is a little late, but it may help other users. You can customize the UI of an application to the UI of the OS:
您还可以尝试 XFileDialog。 还没有尝试过,但看起来值得评估。
You can also try XFileDialog. Haven't tried it much yet but looks worth evaluating.
我围绕 JavaFX 的文件选择器(如果可用)编写了一个包装器。 如果包含在您的应用程序中,您可以替换
为
它然后将使用底层平台的本机(和现代)文件选择器。 并非所有内容都 100% 相同,因此请务必事后进行测试,但大多数事情都会顺利进行。
I wrote a wrapper around JavaFX' file chooser if available. If included in your application, you can replace
with
It will then use the native (and modern) file chooser of the underlying platform. Not everything works 100% the same, so make sure to test it afterwards, but most things should go smoothly.
正如 @htw 所说,如果外观和感觉是您主要关心的问题,请使用 FileDialog。 通过使用FileDialog请注意,有很多方便的方法您将无法使用...
我使用了VFSJFileChooser 几次。 它不会遭受 JFileChooser 错误(由于 zip 文件而加载缓慢,仅限 Windows),但界面不是“本机”。
As @htw said use FileDialog if the look and feel is your main concern. By using FileDialog be aware that there a lots of convenience methods that you won't be able to use...
I used VFSJFileChooser few times. It doesn't suffer from the JFileChooser bugs(slow to load because of zip files, windows only), but the interface is not "native".