Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JFileChooser DIRECTORIES_ONLY problem

darrylburkeOct 27 2008 — edited Oct 28 2008

WinXP SP3, Java 1.6.0_10-beta.

As I understood it, JFileChooser returns the directory whose contents are listed via getCurrentDirectory() and the file or directory selected in the list via getSelectedFile() (may be null). I've given this advice myself in the past.
[http://forums.sun.com/thread.jspa?threadID=5285236&start=2]

So has BoBear
[http://forums.sun.com/thread.jspa?threadID=5308380&start=3]
[http://forums.sun.com/thread.jspa?threadID=722884&start=5]

Well, it doesn't. Please run the code, which will display a JFileChooser 4 times and exit.
-- The first time, click the Open button without clicking elsewhere.
-- The second time, click on a folder (say Java) then click the open button
-- The third time, double-click a folder (say Java) to display its contents, then click the Open button
-- The fourth time, double click a folder (say Java) to display its contents, then click on a folder (say jre6), then click the open button.

This is the output I get:

Current directory set to: C:\Program Files
Selected file is: null

Current directory returned: C:\
Selected file returned: C:\Program Files
--------------------------
Current directory set to: C:\Program Files
Selected file is: null

Current directory returned: C:\Program Files
Selected file returned: C:\Program Files\Java
--------------------------
Current directory set to: C:\Program Files
Selected file is: null

Current directory returned: C:\Program Files
Selected file returned: C:\Program Files\Java
--------------------------
Current directory set to: C:\Program Files
Selected file is: null

Current directory returned: C:\Program Files\Java
Selected file returned: C:\Program Files\Java\jre6
--------------------------
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 25 2008
Added on Oct 27 2008
9 comments
565 views