This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FileDialog for multiple file selection

 
netharam ram
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
netharam ram
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Guy Weiss
Greenhorn
Posts: 2
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic