No Property Events are fired with JFileChooser

Hello,

I'm trying to use the JFileChooser class and I have a problem on which I've been already wasting for more than 2 days. I don't know whether it is normal, but if I implement an accessory with :

JFileChoose fc =new JFileChooser();

fc.setAccessory(new ImagePreview(fc));

The class ImagePreview displays a thumbnail of the selected file (if a picture). In this class, , I have implemented the listener :

fc.addPropertyChangeListener(this);

When running my program, I noticed an strange behaviour if multiple selections are allowed.

If I select only one image name, the picture displays correctly in the preview panel.

If I select many (one by one) the image does not change. I checked with a trace (I've just added a System.out.println)the listener gets control only on the firstselected item.

Is it normal ?

In fact, I'd like to select (or not select) a picture depending on what I'm seeing from the Preview panel (but of course, without deselecting items already selected. )

Is there a solution ? Thanks in advance for help

Gege

[1224 byte] By [martinelligegea] at [2007-10-2 6:22:24]
# 1

If you're listening the for "SelectedFileChangedProperty" on the file chooser then it will always tell you the first file in the selection, not the one that was just added/removed.

At a guess, you should be listening for the "SelectedFilesChangedProperty" (plural!) to get a list of all the files that are selected.

Another guess: if you want to know the files that have just been added to the selection you should remember the previous selection and difference it with the new selection (probably just using suitable Collections).

Not sure if this it what you're after (and don't ask me why JFileChooser has such an odd selection model).

Hope this helps.

KPSeala at 2007-7-16 13:24:09 > top of Java-index,Desktop,Core GUI APIs...
# 2
Thanks a lot, it's exactly what I needed as information. Have a nice dayGege
martinelligegea at 2007-7-16 13:24:09 > top of Java-index,Desktop,Core GUI APIs...