Problem with JFileChooser - very slow
843807May 24 2004 — edited May 30 2004I've built an Applet that by a button pressing, open a JFILECHOOSER to select multiple files. When I select the files and press OPEN, the dialog is very slowly, for 900 files about five minutes to continue the normal process. I use this applet in Windows and JDK 1.4.1_02.
There is a workaround or resolution for this inconvenience.
This is my code for management FILECHOOSER:
// create file chooser
JFileChooser filePicker = new JFileChooser();
// allow only selection of directories
filePicker.setFileSelectionMode(JFileChooser.FILES_ONLY);
// multiple file selection allowed
filePicker.setMultiSelectionEnabled(true);
// no "all files" option
filePicker.setAcceptAllFileFilterUsed(false);
// set a filter to show only "good" files or directories
ChoosableFileFilter filter = new ChoosableFileFilter(FILTER_EXT, FILTER_DESC);
filePicker.setFileFilter(filter);
// show the dirchooser in a pop-up
int returnVal = filePicker.showOpenDialog((Component) e.getSource());
if (returnVal == JFileChooser.APPROVE_OPTION) {
// get all selected files and add them to the fileList
File[] selectedFiles = filePicker.getSelectedFiles();
// Clear all element il list
fileListModel.clear();
for (int i =0; i <selectedFiles.length; i++) {
fileListModel.addElement(selectedFiles);
} // end for
} // end approve if