javawindowsjfilechooserlook-and-feel

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:

How do I get it in Java?


Solution

  • 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.