The Java Developers Almanac 1.4


Order this book from Amazon.

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

e904. Listening for Changes to the Current Directory in a JFileChooser Dialog

    final JFileChooser chooser = new JFileChooser();
    
    // 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())) {
                JFileChooser chooser = (JFileChooser)evt.getSource();
                File oldDir = (File)evt.getOldValue();
                File newDir = (File)evt.getNewValue();
    
                // The current directory should always be the same as newDir
                File curDir = chooser.getCurrentDirectory();
            }
        }
    }) ;

 Related Examples
e903. Listening for Changes to the Selected File in a JFileChooser Dialog
e905. Listening for Approve and Cancel Events in a JFileChooser Dialog

See also: Hidden Files    Icons    Layout    Selections   


© 2002 Addison-Wesley.