wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes using FileDialog for to select both files AND directories Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "using FileDialog for to select both files AND directories" Watch "using FileDialog for to select both files AND directories" New topic
Author

using FileDialog for to select both files AND directories

Allasso Travesser
Ranch Hand

Joined: Feb 06, 2010
Posts: 35
Hi,

For the sake of Mac users I wish to use FileDialog for file/directory selection. I can use:

System.setProperty(apple.awt.fileDialogForDirectories, true)

in order to be able to select directories, but it only allows directory selection. Not setting it only allows file selection. I wish to be able to select either a file OR a directory, which I haven't found a way to do.

Anyone know how?

thanks, Allasso
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

If it's possible to switch to JFileChooser you can use its setFileSelectionMode method.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Allasso Travesser
Ranch Hand

Joined: Feb 06, 2010
Posts: 35
it is possible, but JFileChooser does not display files in "column view mode" that Mac users are accustomed to, thus the reason for using FileDialog.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Allasso Travesser wrote:it is possible, but JFileChooser does not display files in "column view mode" that Mac users are accustomed to, thus the reason for using FileDialog.


I don't have a mac to test this on, but I wonder if this Look & Feel dependent? If so, then JFileChooser could work out just fine.
Allasso Travesser
Ranch Hand

Joined: Feb 06, 2010
Posts: 35
yes, it has the Mac look and feel (sorta) but it displays in what Mac would call "list view mode". I use a Mac and am pretty familiar with this stuff. I know LOTS of Mac users, and "column view mode" is what most of them use. (actually I can't ever remember seeing anyone NOT using column view). I've written several programs that use a file chooser, and I always use FileDialog (if the system detects a Mac) for this reason. Only thing is now I have an application that needs to have the option of selecting either a folder or file.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

BeForthrightWhenCrossPostingToOtherSites
http://forums.sun.com/thread.jspa?threadID=5451009


luck, db
There are no new questions, but there may be new answers.
Allasso Travesser
Ranch Hand

Joined: Feb 06, 2010
Posts: 35


Mia Culpa.

Thank you, Darryl, I just read the etiquette on this in the "How to ask" section. My apologies.

Please forgive if I have ticked anyone off.

Allasso
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Allasso Travesser wrote:I always use FileDialog (if the system detects a Mac)

+1. It's the right thing to do on OS X.

Only thing is now I have an application that needs to have the option of selecting either a folder or file.

Check out the "apple.awt.fileDialogForDirectories" property: http://lists.apple.com/archives/java-dev/2010/May/msg00149.html

The "com.apple.macos.use-file-dialog-packages" property may also be of interest in that context: http://developer.apple.com/legacy/mac/library/#technotes/tn/tn2042.html
Allasso Travesser
Ranch Hand

Joined: Feb 06, 2010
Posts: 35
Lester Burnham wrote:Check out the "apple.awt.fileDialogForDirectories" property: http://lists.apple.com/archives/java-dev/2010/May/msg00149.html


Thanks, Lester, that is what I always use. But as I said in the OP, when that is set true, ONLY directories are selectable. Am I missing something here that you are trying to point out to me?

The "com.apple.macos.use-file-dialog-packages" property may also be of interest in that context: http://developer.apple.com/legacy/mac/library/#technotes/tn/tn2042.html


Thanks, I'll look into that and let you know the outcome.

Allasso
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Am I missing something here that you are trying to point out to me?

Arg, sorry, I totally overlooked that that was precisely what you mentioned.

Thanks, I'll look into that and let you know the outcome.

It won't help with your problem, it's just something to be aware of (and potentially use) if the distinction between files and directories is important.
Allasso Travesser
Ranch Hand

Joined: Feb 06, 2010
Posts: 35
Lester Burnham wrote:It won't help with your problem, it's just something to be aware of (and potentially use) if the distinction between files and directories is important.


Yes, I saw that, and I really appreciate you pointing that out to me. I was unaware of that, and it is something I will use to keep users from navigating into bundles.

Thanks, Allasso
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: using FileDialog for to select both files AND directories
 
Similar Threads
Print to File
another VA - directory listing
slecting mutiple files in a FileDialog (Urgent)
Setting a filename filter in Filedialog
Selecting Directory using Dialog box