Why does it JFileChooser take long time if some of the mounted (net use) network drives (on MS windows platform) are temporarily disconnected ?

Sandip Chitale

Problem Definition :

The JFileChooser tries to connect to all the drives from 'C:' to 'Z:' when instantiated to look for the root directory of each drive. This is done so that the JComboBox of drives can be populated. If any of the drives was a network drive and for some reason disconnected the check for the root directory has to timeout before it returns the disconnected status. In that case the the drive is not included in the JComboBox of JFileChooser. This may take a few seconds for each drive. Thus it takes a while for JFileChooser to come up. The user may think that the application has crashed.

Some drives may indeed be found connected. Then the JFileChooser comes up. However between that time and when the user selects a drive it might have been disconnected. In that case user gets the error dialog anyways. Thus the failure mode in case of first having checked for network drive vs not is the same. The complete set of drives on MS windows platform is not unknowable (considering UNC names are not supported by the JFileChooser anyways).

This has other disadvantage. If a drive that is not in the JComboBox gets connected after the creation of JFileChooser the user may not be able access it (if the application kept on reusing the JFileChooser instance and did not allow the mechanism to refresh it).

So why not populate the all the drive letters in the JComboBox in the first place. In absense of which, at least a refresh JComboBox button should be provided on the JFileChooser.


Install a custom subclass of -


using the any of the following ctors -


public JFileChooser(FileSystemView fsv)

    Creates a JFileChooser using the given FileSystemView


public JFileChooser(File currentDirectory,
                    FileSystemView fsv)

    Creates a JFileChooser using the given current directory and FileSystemView


public JFileChooser(String currentDirectoryPath,
                    FileSystemView fsv)

    Creates a JFileChooser using the given current directory path and FileSystemView

In the javax.swing.filechooser.WindowsFileSystemView subclass override the -

public File[] getRoots();
to return all drive letters from 'A:' to 'Z:'
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact