4

When I create a JFileChooser on a system with a disconnected network drive it takes forever before the JFileChooser gets displayed. It blocks the EDT for about 20s with a single disconnected network drive.

It seems like it would be a common problem, but I can't find a way to work around it. Possible options I've seen are:

  • use JFileDialog
  • replace FileSystemView with one where getRoots() returns a fixed list of drives
  • switch to a WAIT cursor before trying to open JFileChooser(s)
  • create a JFileChooser at startup and keep it around forever
  • try using xfiledialog

My use case is so simple that I hate to resort to a third party library. The other options all seem pretty bad to me though.

Any other suggestions?

Maybe the guy who submitted this bug report 13 years ago is hanging around here and has it figured out by now.

Updated With Code and Logging Output

Here's the code I'm using for this.

private void initFileChooser() {
    log.debug("Initializing fileChooser.");

    fileChooser = new JFileChooser();
    log.debug("FileChooser instantiation complete.");

    fileChooser.setFileFilter(new FileNameExtensionFilter("PDF Files", "pdf"));
    log.debug("File filter setup complete.");

    fileChooser.setMultiSelectionEnabled(false);
    log.debug("Multi-selection disabled.");

    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    log.debug("File selection mode set to files only.");
}

Here's the logging output when the above code runs with no disconnected network drives.

05:37:13.126 [AWT-EventQueue-0] DEBUG - Initializing fileChooser.
05:37:13.481 [AWT-EventQueue-0] DEBUG - FileChooser instantiation complete.
05:37:13.482 [AWT-EventQueue-0] DEBUG - File filter setup complete.
05:37:13.482 [AWT-EventQueue-0] DEBUG - Multi-selection disabled.
05:37:13.482 [AWT-EventQueue-0] DEBUG - File selection mode set to files only.

Here's the logging output when the above code runs with a disconnected network drive on Windows 7. I'm creating a disconnected network drive by using ExpanDrive (1.8.4) to connect to a Linux machine and shutting down the Linux machine after the initial connection is made.

05:37:58.953 [AWT-EventQueue-0] DEBUG - Initializing fileChooser.
05:38:11.108 [AWT-EventQueue-0] DEBUG - FileChooser instantiation complete.
05:38:11.110 [AWT-EventQueue-0] DEBUG - File filter setup complete.
05:38:11.110 [AWT-EventQueue-0] DEBUG - Multi-selection disabled.
05:38:11.110 [AWT-EventQueue-0] DEBUG - File selection mode set to files only.
Community
  • 1
  • 1
Ryan J
  • 2,502
  • 5
  • 31
  • 41
  • You might look to roll your own using [this source](http://codereview.stackexchange.com/questions/4446/file-browser-gui) as a starting point. – Andrew Thompson Sep 06 '12 at 05:03
  • *"Maybe the guy who submitted this bug report 13 years ago is hanging around here and has it figured out by now."* If they did not mention it as a workaround in the bug report (the best place for such information), why would they mention it now? ..Or was that sarcasm? – Andrew Thompson Sep 06 '12 at 05:08
  • aaaach Now I see that some users with hot head deleted my post to your `FileBro` about hanging issue on `WinXP` for `Network Drives` and `My Network`, – mKorbel Sep 06 '12 at 06:18

1 Answers1

-1

you blocked EDT, maybe with RepaintManager exceptions in the case that Network Drive isn't accesible or returns an exception, your have to

  • use SwingWorker or Runnable#Thread

  • notify user "Please wait, whatever ...."

  • if success, then to show JFileChooser with Files

  • otherwise you GUI freeze until network drive returns content or exception

mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • 1
    The delay happens when I call `new JFileChooser()`. That call must be made on the EDT accoring to [this](http://stackoverflow.com/questions/491323/is-it-safe-to-construct-swing-awt-widgets-not-on-the-event-dispatch-thread) answer. I've updated my question with sample code and logging output. – Ryan J Sep 06 '12 at 11:56
  • not when Folder is once time opened, then File contents from channel is cached untill ticked expired (depend of Native OS and HW on Network side), – mKorbel Sep 06 '12 at 13:01
  • Previously up-voted as conceptually correct. The worker will have to do whatever is required to minimize latency when `JFileChooser` is later invoked on the EDT. For example, I have a USB spindle with a hard-coded spindown timer on which I simply `touch` a hidden file at a slightly shorter interval. – trashgod Sep 06 '12 at 19:07