8

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: Image from here: http://stackoverflow.com/questions/10745198/how-to-use-the-default-file-chooser-for-the-operating-system-java

And there is that one, for example used by Chrome: Other windows native file chooser

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?

piegames
  • 975
  • 12
  • 31

3 Answers3

7

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.

Community
  • 1
  • 1
Edv Beq
  • 910
  • 3
  • 18
  • 43
1

I was also looking for this function. I found two ready-to-use libs:

I just tested the JavaFX approach which works in a test environment. But it needs JavaFX. It is advertised with a fall-back to Swing widgets if no JavaFX is installed on the target platform (fall-back not tested). Offers also a Maven artifact. The 2nd is just for Windows (not tested).

Maybe this will help someone who is looking for this feature.

Hani
  • 271
  • 3
  • 6
0

I was looking for this, just like everyone else. And after putting up with not exactly what I needed libraries for more than two years, I built my own. This version is currently in pre-release, and I am the owner, but it may be what people need.
The issue with JavaFX, for me, is it is a big library. And adding that powerful of a library just to use it for the FileDialog is a bit of a waste.
I loved JNAFileChooser unit I saw they were using the older directory chooser.
I attempted to make the api simple, and I tried to document the best I could. Feel free to check it out, you can find all the jars under release.
JWindowsFileBrowser