• Post Reply Bookmark Topic Watch Topic
  • New Topic

FileDialog and JFileChooser

 
Elena Dove
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

Could you explain me what the difference between the FileDialog and JFileChooser.
The FileDialog saves the last used directory (last path), if the Java-Program was restartet, but JFileChooser does not.
I have a task to make the File Chooser that saves the last path. I am not sure if it is a good idea to use FileDialog. I know that mix AWT and Swing components is not a good idea. Or is there another way to save the last path?

Any advises?
Thanks a lot!
 
Brian Cole
Author
Ranch Hand
Posts: 920
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Elena Dove:
Hello all,

Could you explain me what the difference between the FileDialog and JFileChooser.

...

I know that mix AWT and Swing components is not a good idea. Or is there another way to save the last path?


There's no problem mixing FileDialog with swing components, since it doesn't interact with any components outside its own Window.

In fact, I recommend FileDialog over JFileChooser when FileDialog suits your needs. FileDialog uses the OS's native file chooser widget while JFileChooser is an imitation of the native widget, and often a poor one.

The problem with FileDialog is that it's pretty limited. It's great if you just want to open a file. But if you want to do something like select a directory, you're pretty much out of luck.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your application is in Swing and uses the default L&F (motif), using the FileDialog will stick out like a sore thumb as it will use the native L&F.

Either :
1) Set the L&F of the application to use the underlying OS L&F. So your FileDialog and your application will appear and behave the same. OR
2) Use a JFileChooser and share the fileChooser instance everytime. So withing one "session" of the application it will remember the last used path. Of course you will have to persist and reload the path accross sessions, if you want to maintain the consistency.

Mixing L&F is a bad usability design.
 
Brian Cole
Author
Ranch Hand
Posts: 920
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Maneesh Godbole:
If your application is in Swing and uses the default L&F (motif), using the FileDialog will stick out like a sore thumb as it will use the native L&F.


We're going to have to agree to disagree here.

In my view, you expect all your apps to use the same native-looking file choosing popups, even if their UI designs differ. Even apps with really weird UIs use the native file popups, at least in my experience. I often find JFileChooser jarring when it appears.

Every once in a while Sun updates the JFileChooser UI delegates to look close to (but not quite) native, then they become out of date as the OSes evolve and the JFileChooser UIs don't.



btw, metal is the default LnF, not motif.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm with Brian on this one. In all Swing applications I've worked on I've provided a switch of which one to use, and the default is always FileDialog. Because that's the one the user is used to. Remembering the last-used directory is rather easy to implement.

There are also platforms (e.g. OS X) where the default L&F is the native one, so that reason not to use FileDialog isn't even true.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Brian Cole:


In my view, you expect all your apps to use the same native-looking file choosing popups, even if their UI designs differ. Even apps with really weird UIs use the native file popups, at least in my experience. I often find JFileChooser jarring when it appears.
btw, metal is the default LnF, not motif.


I was under the impression that Sun came up with the "Swing" concept precisely because of this reason of different L&F on different platforms and different flavors of the same platform (98,98SE,2K,Xp etc.)
My point was, if I am working on XP, I would appreciate it if all the L&F of all applications would look and behave similarly. Thats the reason I always make it a point to set the L&F of all my applications to the native L&F. On the other hand, if I am using the default LAF (metal and not motif as you rightly pointed out, I slipped there) and on clicking something I am presented with a dialog with a native LAF I am going to be a bit jarred. But then to each his own. Thats how all the usability consultants mint money (wink!). So I agree. Lets agree to disagree because usability is very much subjective.


Originally posted by Ulf Dittmer:

There are also platforms (e.g. OS X) where the default L&F is the native one, so that reason not to use FileDialog isn't even true.


My bad here. I have never worked on anything but windows. Once I did managed to install VMWare and Fedora. But somehow I couldnt get my screen resolution to change more than 800x600 and finally I gave it up in frustration.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!