JFileChooser Question

I have a JFileChooser that allows the user to select multiple image files to create a slideshow. I want to show the files in the order that the user selected them with the JFileChooser. The problem is that the JFileChooser returns the files via the getSelectedFiles() in sorted order, sorted by file name, and I need to know the order that the user selcted the files in. Is there any way to gather this information? Any help is appreciated, thanks for your time.

[469 byte] By [Malcolm_Fa] at [2007-11-27 5:08:58]
# 1

That would be a neat trick. At the very least I would think that you would have to extend JFileChooser and intercept the events firing when the user selects a file to keep up with which one was added to the selected collection when. I'm not even sure it's possible to get hold of the things you would need to to make it work.

It's a very neat idea though.

PS.

puckstopper31a at 2007-7-12 10:28:32 > top of Java-index,Java Essentials,Java Programming...
# 2
The only way would be to find the JList that is used to list the files in the chooser and add a listener to it to get the selection changes as they happen.
bsampieria at 2007-7-12 10:28:32 > top of Java-index,Java Essentials,Java Programming...
# 3

Typically file choosers don't provide this information, so you would be making a user interface innovation. This is often a bad idea as users know how file choosers work and don't care to be surprised by innovations.

Besides, your question is not completely well-defined. It's possible to select a group of files all at once using shift-click (or some similar keystroke). And then it's possible to unselect something in the middle of that group using control-click (or similar).

DrClapa at 2007-7-12 10:28:32 > top of Java-index,Java Essentials,Java Programming...
# 4
An alternative solution would be to allow the users to select the files, and put them in a list. Then have the list support drag-n-drop to reorder the list if they want to.
bsampieria at 2007-7-12 10:28:32 > top of Java-index,Java Essentials,Java Programming...
# 5
That's a good idea. If you're going to process the files in a certain order, presumably because it makes a difference which order you process them in, then it would help to give the user visual feedback about that order.
DrClapa at 2007-7-12 10:28:32 > top of Java-index,Java Essentials,Java Programming...
# 6
JFileChooser savechooser = new JFileChooser();savechooser.setDialogTitle("Save a file...");savechooser.setMultiSelectionEnabled(true);
Reona at 2007-7-12 10:28:32 > top of Java-index,Java Essentials,Java Programming...