Module java.desktop
Package javax.swing

Class JFileChooser

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

          description="A component which allows for the interactive selection of a file.")
public class JFileChooser
extends JComponent
implements Accessible
JFileChooser provides a simple mechanism for the user to choose a file. For information about using JFileChooser, see How to Use File Choosers, a section in The Java Tutorial.

The following code pops up a file chooser for the user's home directory that sees only .jpg and .gif images:

    JFileChooser chooser = new JFileChooser();
    FileNameExtensionFilter filter = new FileNameExtensionFilter(
        "JPG & GIF Images", "jpg", "gif");
    int returnVal = chooser.showOpenDialog(parent);
    if(returnVal == JFileChooser.APPROVE_OPTION) {
       System.out.println("You chose to open this file: " +

Warning: Swing is not thread safe. For more information see Swing's Threading Policy.