The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.swing.filechooser  [19 examples]

e891. Getting and Setting the Current Directory of a JFileChooser Dialog

    JFileChooser chooser = new JFileChooser();
    
    try {
        // Create a File object containing the canonical path of the
        // desired directory
        File f = new File(new File(".").getCanonicalPath());
    
        // Set the current directory
        chooser.setCurrentDirectory(f);
    } catch (IOException e) {
    }
    
    // The following method call sets the current directory to the home directory
    chooser.setCurrentDirectory(null);
    
    // Show the dialog; wait until dialog is closed
    chooser.showOpenDialog(frame);
    
    // Get the current directory
    File curDir = chooser.getCurrentDirectory();

 Related Examples
e887. Creating a JFileChooser Dialog
e888. Displaying Only Directories in a File Chooser Dialog
e889. Adding a Filter to a File Chooser Dialog
e890. Determining If the Approve or Cancel Button Was Clicked in a JFileChooser Dialog
e892. Getting and Setting the Selected File of a JFileChooser Dialog
e893. Getting the File-Type Name of a File
e894. Copying the Filename Path from a JFileChooser Dialog to the Clipboard

See also: Events    Hidden Files    Icons    Layout    Selections   


© 2002 Addison-Wesley.