JFileChooser Multiple File Selection

Hello all, I am having a little issue with JFileChooser in particular the multiple file selection facility. Although I am able to select multiple files I cannot open the same file twice, even if I type the file name twice!!

Is it possible to open 1 file twice? If so how?

Cheers people!

[305 byte] By [gurdz_studenta] at [2007-10-2 16:39:37]
# 1
Some OS'es won't let the same file be opened several times, some will.
BIJ001a at 2007-7-13 17:47:49 > top of Java-index,Java Essentials,Java Programming...
# 2
What do you mean by "open" in this context? And for that matter, what do you mean by "cannot open"? Error messages? Program hangs? You get an electric shock from the mouse?
DrClapa at 2007-7-13 17:47:49 > top of Java-index,Java Essentials,Java Programming...
# 3

> What do you mean by "open" in this context? And for

> that matter, what do you mean by "cannot open"? Error

> messages? Program hangs? You get an electric shock

> from the mouse?

Apologies for being vague, when i say "cannot open" I mean that if I type in the open file dialog pop up that opens as part of JFileChooser a file name twice, it is only loaded into the list of selected files once. All i can think is that the getSelectedFiles() method is not returning the file the second time round.

The following code is what I have hope this helps:

JFileChooser chooser = new JFileChooser();

ArrayList selectedFilesArray = null;

chooser.setMultiSelectionEnabled(true);

if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {

File selectedFile[] = chooser.getSelectedFiles();

selectedFilesArray = new ArrayList();

for(int i=0; i<selectedFile.length; i++){

if(selectedFile[i].getAbsolutePath().endsWith(".txt") == true){

selectedFilesArray.add(selectedFile[i]);

}

}

dataFileArray.add(selectedFilesArray);

}

>

gurdz_studenta at 2007-7-13 17:47:49 > top of Java-index,Java Essentials,Java Programming...
# 4

> What do you mean by "open" in this context? And for

> that matter, what do you mean by "cannot open"? Error

> messages? Program hangs? You get an electric shock

> from the mouse?

... you get a phone call from somebody you've never heard of, yelling: "Stop doing that !" ?

da.futta at 2007-7-13 17:47:49 > top of Java-index,Java Essentials,Java Programming...
# 5
> You get an electric shock from the mouse?I hear there's a pending lawsuit against Disney for that very thing. Mickey's been naughty.
yawmarka at 2007-7-13 17:47:49 > top of Java-index,Java Essentials,Java Programming...
# 6

> Apologies for being vague, when i say "cannot open" I

> mean that if I type in the open file dialog pop up

> that opens as part of JFileChooser a file name twice,

> it is only loaded into the list of selected files

> once. All i can think is that the getSelectedFiles()

> method is not returning the file the second time

> round.

But... if it's got the same name, isn't it the same file ?

da.futta at 2007-7-13 17:47:49 > top of Java-index,Java Essentials,Java Programming...
# 7

> But... if it's got the same name, isn't it the same

> file ?

Well you are right but the situation is I am iterating through the list of selected files and if a file is selected twice or the file name typed in twice one after the other or after several other different files that are selected, it is not added to the list of File objects that is contained within the JFileChooser object.

Is there a line of code that allows this or is it just not possible?

gurdz_studenta at 2007-7-13 17:47:49 > top of Java-index,Java Essentials,Java Programming...
# 8

If I were designing a file chooser, I would filter out duplicate file names too. After all, it's a visual component and there's no visual metaphor for having selected a file twice.

However: you can look in the API documentation as well as I can. The name of the method would be something like "allowDuplicateFiles".

DrClapa at 2007-7-13 17:47:49 > top of Java-index,Java Essentials,Java Programming...
# 9

> However: you can look in the API documentation as

> well as I can. The name of the method would be

> something like "allowDuplicateFiles".

I am having some difficulty finding such method and am wondering if such method actually exists, can anyone confirm whether it is posible to select duplicate files?

gurdz_studenta at 2007-7-13 17:47:49 > top of Java-index,Java Essentials,Java Programming...