posted 19 years ago
hello all,
I'm currently having a problem with using the FileFilter object to apply a choosable file filter to the JFileChooser. Unfortunately I don't have access to my code right this minute but I was hoping that someone might be able to point me in the right direction of where to start looking for the problem.
Currently I have a JFileChooser used to browse files. I need several file filters, however, I can't statically code them, e.g., code a seperate class for each and etc., What I've done extended the FileFilter class and added a method to accept an array of extensions and a filter description.
In the constructor for my panel that displays my file browser, I iterate through a 2-d array that contains a file description tied to an array of extensions. I then create new instances of my FileFilter class based on this array.
Now, when I launch the JFileChooser, I get my list of filters in the drop down and the first time I select a filter it correctly filters the contents of the directory. Unfortunately, if I choose a different filter and go back .. ok clarification:
I have 4 filters, A,B,C,D, (A representing the All Files filter). Say I'm looking at a directory that only has files of type B and then some misc. files that only show up in the All Files filter. The first time I look at that directory and choose B, it will correctly filter the files however, if I then select a different filter and go back to B, B now displays all files in the directory. Now, If I originally select a filter that doesn't apply to any files in the current directory, say filter C, this behavior doesn't happen, e.g., Select C, no files displayed, select A, all files displayed, select C, no files displayed.
If I close the file browser and then launch it again (note, not closing the panel that contains the button to launch the file browser, just the browser) this behavior persists.
I'm stumped - any input would be greatly appreciated.
Thanks!