java JFileChooser 的替代品

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/759376/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 13:39:44  来源:igfitidea点击:

Alternative to JFileChooser

javauser-interfacejfilechooser

提问by gizmo

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.

我请求对当前使用 JFileChooser 的小程序进行一些更改。
主要的抱怨之一是文件选择器使用起来很麻烦,因为它的行为与本机小部件不同,尤其是在导航到根级别时。

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.

因此,知道 JFileChooser 遇到的所有其他问题(例如 Windows 上的 zip 文件缓存...),我想知道 Java 世界中是否存在可行的替代方案。

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?

当然,有使用原生小部件的 SWT,但将小程序大小增加 25 并不是一个真正的选择。那么,有没有更好的文件选择器纯 Java 实现呢?

采纳答案by Touko

You can also try XFileDialog. Haven't tried it much yet but looks worth evaluating.

您也可以尝试XFileDialog。还没有尝试过很多,但看起来值得评估。

回答by hbw

The AWT FileDialogactually does use the native component, but as with most AWT vs. Swing issues, it's much less flexible and customizable than Swing's JFileChooser. So there's a tradeoff: JFileChoosermay 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 with FileDialog.

AWTFileDialog实际上确实使用了本机组件,但与大多数 AWT 与 Swing 的问题一样,它比 Swing 的JFileChooser. 所以有一个权衡:JFileChooser可能有一个笨重的用户界面,但它通常对大多数用途更好。但是,如果您真的希望您的文件选择对话框看起来和感觉像原生对话框,那么您可以使用FileDialog.

回答by chama

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:

我知道这有点晚了,但它可能会帮助其他用户。您可以将应用程序的 UI 自定义为操作系统的 UI:

try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {e.printStackTrace();     }

回答by Veluria

I wrote a wrapperaround JavaFX' file chooser if available. If included in your application, you can replace

如果可用,我围绕 JavaFX 的文件选择器编写了一个包装器。如果包含在您的应用程序中,您可以替换

JFileChooser fileChooser = new JFileChooser();

with

JFileChooser fileChooser = new NativeJFileChooser();

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.

然后它将使用底层平台的本机(和现代)文件选择器。并非一切都 100% 相同,因此请确保事后对其进行测试,但大多数事情应该会顺利进行。

回答by Veluria

As @htw said use FileDialogif the look and feel is your main concern. By using FileDialogbe aware that there a lots of convenience methods that you won't be able to use...

正如@htw 所说,如果外观和感觉是您的主要关注点,请使用FileDialog。通过使用FileDialog 请注意,有很多您将无法使用的便捷方法......

I used VFSJFileChooserfew times. It doesn't suffer from the JFileChooser bugs(slow to load because of zip files, windows only), but the interface is not "native".

我用过几次 VFSJFileChooser。它不会受到 JFileChooser 错误的影响(由于 zip 文件加载缓慢,仅限 Windows),但界面不是“原生”的。