Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows native File chooser in java

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?

like image 303
piegames Avatar asked Oct 02 '16 16:10

piegames


1 Answers

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.

like image 56
Edv Beq Avatar answered Sep 28 '22 16:09

Edv Beq