JFileChooser vs JDialog vs FileDialog

2019-05-24 07:00发布

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.

1条回答
够拽才男人
2楼-- · 2019-05-24 07:23

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()).

查看更多
登录 后发表回答