File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes JFileChooser: setSelectedFile() hangs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JFileChooser: setSelectedFile() hangs" Watch "JFileChooser: setSelectedFile() hangs" New topic

JFileChooser: setSelectedFile() hangs

Guido Sautter
Ranch Hand

Joined: Dec 22, 2004
Posts: 142
Hi Ranchers,

I have a problem with JFileChooser under Windows XP (JVM version doesn't seem to matter, tried 1.4.2 and above):

The setSelectedFile() method hangs up inside JFileChooser, but only if the file previously selected is located in the user's Desktop. If the previous file resides in other sub folders of 'Documents and Settings/<userName>/...', it works OK, so it's probably not a matter of the spaces in the path.

Under Windows 2000, it works fine.

Does anyone have similar experiences, maybe even a solution or workaround? Google didn't produce any helpful results.

Thanks in advance,
G Estes
Ranch Hand

Joined: Oct 22, 2002
Posts: 62
Can you post some code as to how you are implementing the file chooser?
Guido Sautter
Ranch Hand

Joined: Dec 22, 2004
Posts: 142
The code belong to a File IO component of the software I write. Here the fields:
- lastSaveFile is an instance filed holding the file last saved to
- model is a method argument, basically providing the format a document was last saved in (XML, txt, etc.)
- selectedFormat is the JFileChooser FileFilter matching the saving format
- fileKeeper is an instance field, ensuring that the file name in the JFileChooserUI has the appropriate extension if the saving format changes

The line that hangs is fileChooser.setSelectedFile(target);

JConsole shows that the invocation of setSelectedFile() hangs somewhere deep inside Swings PLaF, in FileView.ensureFileVisible(), with some Win32 classes in the stack trace. The final blocking occurs on Unsafe.wait().

Thanks for any ideas.
I agree. Here's the link:
subject: JFileChooser: setSelectedFile() hangs
jQuery in Action, 3rd edition