Wednesday, May 8, 2013

Complete Guide to JFileChooser

The JFileChooser Swing component let's users explore files on their system. It provides a GUI similar to Windows Explorer found in Windows or Nautilus in Ubuntu. It allows users to navigate through their file system and choose the desired file/directory.
You can use a JFileChooser to open or save files from/to a location which is chosen by the user. Here's a complete guide explaining the use of JFileChooser and it's important properties.

Before we begin, one important thing to note is that JFileChooser is a modal dialog. Whenever a modal dialog is displayed the program execution is paused until an action occurs on the user part. For Ex:

showJFileChooserDialog();
System.out.println("I have to WAIT until an action by the user");

Let us begin with a simple application scenario where you want to display the user's picture on your app's form. Here's the design view of the sample app we gonna develop.