Java中的Windows本机文件选择器 [英] Windows native File chooser in java

查看:1096
本文介绍了Java中的Windows本机文件选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显然,Windows(10)上有(至少?)两个不同的本机文件选择器.有一个供JFileChooser和其他程序使用的程序:

Apparently, there are (at least?) two different native File choosers on Windows (10). There is this one, which is used by JFileChooser and other programs:

有一个,例如Chrome使用的一个:

And there is that one, for example used by Chrome:

我比第一个更喜欢它,因为:

I like it much more than the first one because:

  • 您可以直接在顶部输入文件路径
  • 您可以搜索文件夹
  • 左侧的直接访问包含整个文件树

如何在Java中获取它?

推荐答案

使用JavaFX库

FileChooser fileChooser = new FileChooser();
fileChoose.showOpenDialog(null);

要在摆动环境中运行它,请查看那些

To run it in a swing context, have a look at those two answers.

PlatformImpl.startup(() -> {
    FileChooserd = new FileChooser();
    d.showOpenDialog(null);
});

 new JFXPanel();
 Platform.runLater(() -> {
     FileChooser d = new FileChooser();
     d.showOpenDialog(null);
 });

请注意,将JavaFX和Swing混合使用时,诸如模式之类的其他功能将不起作用.另外,您将必须构建一些代码,这些代码要等到Runnable完成后才能获取结果.

Note that other things like modality won't work when mixing JavaFX and Swing. Also, you will have to build some code that waits until the Runnable has finished to be able to fetch the results.

本地文件对话框提供了本地文件对话框,而

native file dialogs provides native file dialogs, and LWJGL 3 provides Java bindings for this library.

这篇关于Java中的Windows本机文件选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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