Alternative to JFileChooser
Asked Answered
R

5

18

I've a request to make some changes to a little applet that currently use a JFileChooser.
One of the main complaints is that the file chooser is a pain in the ass to use because it behaves differently than the native widget, especially for navigating up to the root level.

So, knowing that and all the other issue JFileChooser suffer (like the zip file caching on windows...), I was wondering that a viable alternative exists in the java world.

Of course, there is SWT that use the native widget, but increasing the applet size by 25 is not really an option. So, is there a better pure java implementation of a file chooser?

Rapper answered 17/4, 2009 at 7:32 Comment(1)
There is a way to open up the standard Windows open dialog form and save as dialog form. I just cannot remember how to do it.Extravagant
I
5

You can also try XFileDialog. Haven't tried it much yet but looks worth evaluating.

Ishtar answered 10/2, 2010 at 8:5 Comment(1)
That's pretty cool, but it's Windows-only and uses JNI. Is there a cross-platform alternative?Larceny
A
12

The AWT FileDialog actually does use the native component, but as with most AWT vs. Swing issues, it's much less flexible and customizable than Swing's JFileChooser. So there's a tradeoff: JFileChooser may have a clunky user interface, but it's usually better for most purposes. If you really want your file choosing dialogs to look and feel like the native ones, though, then you can go with FileDialog.

Anglesey answered 17/4, 2009 at 8:15 Comment(1)
I read here that FileDialog is not very platform independent. Any 2023 solutions that are Swing compatible (e.g. not JavaFX)?Multiplication
M
6

I know this is a little late, but it may help other users. You can customize the UI of an application to the UI of the OS:

try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {e.printStackTrace();     }
Madera answered 2/3, 2010 at 5:29 Comment(2)
I'm pretty late here as well but its worth noting that while this does a pretty good job, the JFileChooser on OS X using the system look and feel is not at all reminiscent of the native dialog.Rhnegative
There is a way in Java to have it open up the windows open and save file dialog window? I just cannot remember how it was done.Extravagant
I
5

You can also try XFileDialog. Haven't tried it much yet but looks worth evaluating.

Ishtar answered 10/2, 2010 at 8:5 Comment(1)
That's pretty cool, but it's Windows-only and uses JNI. Is there a cross-platform alternative?Larceny
G
3

I wrote a wrapper around JavaFX' file chooser if available. If included in your application, you can replace

JFileChooser fileChooser = new JFileChooser();

with

JFileChooser fileChooser = new NativeJFileChooser();

It will then use the native (and modern) file chooser of the underlying platform. Not everything works 100% the same, so make sure to test it afterwards, but most things should go smoothly.

Gibert answered 13/6, 2017 at 9:20 Comment(1)
Thanks @Veluria! My initial tests are great - this uses OS dialogs just as any application should be able to do, and seems to work well (checked OSX & Win10)Demirep
S
0

As @htw said use FileDialog if the look and feel is your main concern. By using FileDialog be aware that there a lots of convenience methods that you won't be able to use...

I used VFSJFileChooser few times. It doesn't suffer from the JFileChooser bugs(slow to load because of zip files, windows only), but the interface is not "native".

Salpiglossis answered 17/4, 2009 at 12:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.