Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JFileChooser: Selecting multiple files error

 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Please have a look at the following code



In this code, I can select multiple files, but I am sure it is NOT selecting multiple files because "text.append("Opening "+file.getName()+"\n New Line\n");" code doesn't show names of multiple selected files, just a one file. Please help me..

Apart from this, I noticed I can't select files by simply CLICK AND DRAG system. How to enable that? Please help...
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why did you choose to call the getSelectedFile method, which obviously returns a File object, rather than the getSelectedFiles method, which obviously returns an array of Files?
 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a LOT for your quick reply. Actually I didn't know about that method because I was just learning about JFileChooser by my self through Oracle tutorials. Here is my new code.



This code works fine but there is a small issue. As you can see, this code accepts an array length of 5, which is fixed. But if someone need to select 30 files at ones, the array length will be insufficient. Is there a way to set the array length according to the number of files that user select? or else should I simply give an big array length like 100 ?
 
Maneesh Godbole
Saloon Keeper
Posts: 11185
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the API to find out what JFileChooser#getSelectedFiles() actually returns.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. You don't decide how big the array is, the JFileChooser returns the array. It decides. You can certainly create your own array, as you did in that code, but that's pointless because the next line of code replaces it with the array returned from the JFileChooser.
 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wow! Thanks for both of your replies. Just gonna check that out, and will come back with the corrected code...

And sorry for the late reply.I didn't get any email notification..
 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OHHH YEAH!! Great, Perfect and excellent!!! This is what I call as learning!!! I did the code, have a look!




Thanks lot for all of you.. Since my primary objective is completed, I am marking this thread as solved, but I have another 2 questions.

I noticed I can't select files by simply CLICK AND DRAG system. How to enable that?

I don't like the way that the open dialog looks. It is just normal as we can see in other software. Got to know this is because of "Jave Look And Feel". Still I haven't learn about this, but if yes, I will definitely learn. Please help.,


 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found the answer for the look and feel.



Now I need an answer only for the CLICK AND DRAG thing. Please help..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic