This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Swing / AWT / SWT and the fly likes FileDialog for multiple file selection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "FileDialog for multiple file selection" Watch "FileDialog for multiple file selection" New topic
Author

FileDialog for multiple file selection

netharam ram
Ranch Hand

Joined: Aug 09, 2001
Posts: 202
Hi,I just want to open a FileDialog to Open more than one file at a time.For eg. in winamp to add mp3 files to the playlist we are able to select even all files of the folder.I want to select some or all files of a folder and add it to a listbox.Again to choose directory as in winamp to add Directory to the playlist I want to add all files of a specific folder using select directory.Please mail to me as soon as possible
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

The only way I know how to do something like that (there is probably a better way) is to allow multiple files to be selected and then getSelectedFiles(File[] someName) throws them into an array of files.
As far as selected a DIR instead of a file, I really don't know, unless you use the FileNameFilter and filter out all but directories.
Good Luck.

------------------
Happy Coding,
Gregg Bolinger


GenRocket - Experts at Building Test Data
netharam ram
Ranch Hand

Joined: Aug 09, 2001
Posts: 202
Hai Gregg, but the problem is not how to get the files selected,but how to select multiple files.when I use ctrl+ to select multiple files the previous slection is lost,even shift+ doesn't work in a FileDialog box.So please help me out to get this job done.If possible attach me a piece of sample code.Urgent please.
better suggestion
Netharam
[This message has been edited by netharam ram (edited September 01, 2001).]
Guy Weiss
Greenhorn

Joined: Oct 11, 2011
Posts: 2
in order to open a FileDialog with the option to choose more than one file you should create the FileDialog with SWT.MULTI style:

FileDialog dialog = new FileDialog(shell,SWT.MULTI);

and then get the results using:

String firstFile = dialog.open();
if(firstFile != null){
String[] files = dialog.getFileNames();
}


Guy
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19679
    
  18

Welcome to the Ranch, Guy!

You probably missed that a) this question is about java.awt.FileDialog, not the SWT FileDialog, and b) netharam ram probably didn't wait 10 years for an answer


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Guy Weiss
Greenhorn

Joined: Oct 11, 2011
Posts: 2
Hi Rob!

I was trying to find a way to multiselect using SWT FileDialog and during my search I saw this quistion..
When I found a solution, I've added it to this post so if someone will google it in about 10 years from now, he'll be able to see the answer
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19679
    
  18

And that's exactly why we don't disapprove of kicks like this. The only reason I replied was because of the AWT vs SWT issue, but people looking for answers will of course also find this thread if they are looking for an SWT answer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: FileDialog for multiple file selection