3

I need to know which of the 3 is best for me. My requirements are as follows in order of importance:

  • Save and load files with ease.
  • File type filter during file selection (not afterwards).
  • Look and feel is exactly the same as the native OS L&F.

If there is a dialog that I've not mentioned that would be more ideal, please let me know.

Perry Monschau
  • 883
  • 8
  • 22
  • 2
    Anything starting J is swing so is unlikely to match native OS that well. JFileChooser allows full filtering, the AWT FileDialog is likely to be better for that. JDialog is a blank dialog!! – Adam Mar 21 '12 at 00:26
  • This much I know already. What I'm really after is a solution that satisfies all 3 bullets. I just simply can't believe that java wouldn't provide such a solution that offers both familiar L&F and a decent filtering system. Is there no way this can be achieved? – Perry Monschau Mar 21 '12 at 00:43

1 Answers1

10

What is the rest of your application written in? If you used AWT you should use FileDialog. If you used Swing you should use JFileChooser. Both classes meet all of your requirements. (A JDialog is simply an empty window, you can only use it to open files if you add a Component to it which allows you to, and JFileChooser already does this for you.)

Saving and loading has to be written with your own methods, both JFileChooser and FileDialog can only be used to select file(s).

Both FileDialog and JFileChooser support file filters during selection.

FileDialog's default UI is the native OS'. JFileChooser's (in fact, your entire applicatin's) UI can be set to the native OS' with UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()).

Jeffrey
  • 44,417
  • 8
  • 90
  • 141
  • FileDialog's file filter sucks. I've tried it. Last I tried setLookAndFeel it didn't change a thing, but I'll give it a go. It may have been a personal error. – Perry Monschau Mar 21 '12 at 00:58
  • @PerryMonschau It may suck, but it's still there. You either need to call `setLookAndFeel` before creating your components or call `SwingUtilities#updateComponentTreeUI` on your highest level container, as the javadoc states. – Jeffrey Mar 21 '12 at 01:02
  • 2
    No, see JFileChooser's inner components have the same L&F, however the layout is not native to the OS. However, the FileDialog does in fact have the native file filter system, I'm just used to a different OS. – Perry Monschau Mar 21 '12 at 01:09