Windows native File chooser in java

我的梦境 提交于 2019-11-27 17:02:42

问题


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:

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

I like it much more than the first one because:

  • You can directly enter your file path at the top
  • Your can search the folder
  • The direct access on the left contains the whole file tree

How do I get it in Java?


回答1:


Use the JavaFX library

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);
 });

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.

Use a special library

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



来源:https://stackoverflow.com/questions/39819319/windows-native-file-chooser-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!