The Java Developers Almanac 1.4


Order this book from Amazon.

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

e900. Displaying the Current Directory in the Title of a JFileChooser Dialog

This example displays the complete path of the current directory in the title whenever the current directory changes.
    final JFileChooser chooser = new JFileChooser();
    
    // Initialize title with current directory
    File curDir = chooser.getCurrentDirectory();
    chooser.setDialogTitle(""+curDir.getAbsolutePath());
    
    // Add listener on chooser to detect changes to current directory
    chooser.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(evt.getPropertyName())) {
                File curDir = chooser.getCurrentDirectory();
    
                chooser.setDialogTitle(""+curDir.getAbsolutePath());
            }
        }
    }) ;

 Related Examples
e898. Changing the Text of the Approve Button in a JFileChooser Dialog
e899. Setting an Accessory Component in a JFileChooser Dialog

See also: Events    Hidden Files    Icons    Selections   


© 2002 Addison-Wesley.