Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4679673

JFileChooser.setSelectedFiles() is very slow for multiple select

XMLWordPrintable

    • b17
    • x86
    • windows_2000



        Name: jk109818 Date: 05/03/2002


        FULL PRODUCT VERSION :
        java version "1.4.0"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
        Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

        FULL OPERATING SYSTEM VERSION :
        Microsoft Windows 2000 [Version 5.00.2195]

        A DESCRIPTION OF THE PROBLEM :
        Calling setSelectedFiles() with a large array of files
        (e.g. 475) on a JFileChooser configured with
        setMultiSelectionEnabled(true) is extremely slow (i.e. 3.5
        minutes). Selecting all files by typing Ctrl-A in the file
        list takes a second or two.

        The bulk of the time is taken by
        MetalFileChooserUI.setFileSelected(). It walks through the
        selectedFiles array comparing it to the array of selected
        values in the JList, then adjusts the JList selection which
        fires a selection property change which starts the whole
        process over again. It's very inefficient.

        It would also be nice if JFileChooser exposed a selectAll()
        method that efficiently selected all files in the list.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        1. Run the attached SelectAllChooser program
        2. Navigate to a directory containing a lot of files (you
        can see the slowness with only 30 files or so, but the more
        files the more obvious)
        3. Press the Select All button in the chooser accessory

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        It takes a very long time to select all the files. The
        program prints how long it took to stdout.

        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.awt.event.*;
        import java.io.*;
        import javax.swing.*;
        public class SelectAllChooser {
        public static void main(String args[]) {
        final JFileChooser fc = new JFileChooser();
        fc.setMultiSelectionEnabled(true);
        JButton btnSelectAll = new JButton("Select All");
        btnSelectAll.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
        long lStart = System.currentTimeMillis();
        File[] files = fc.getCurrentDirectory
        ().listFiles();
        fc.setSelectedFiles(files);
        System.out.println("time " +
        (System.currentTimeMillis() - lStart) + "ms");
        }
        });
        fc.setAccessory(btnSelectAll);
        fc.showOpenDialog(null);
        System.exit(0);
        }
        }
        ---------- END SOURCE ----------

        CUSTOMER WORKAROUND :
        You can type Ctrl-A in the list to select all files, but
        users do not know this which is why I am providing a
        button. It would be nice if there was some way to have the
        button programmatically invoke the "selectAll" Action on
        the JList.
        (Review ID: 146137)
        ======================================================================

              leifs Leif Samuelsson (Inactive)
              jkimsunw Jeffrey Kim (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: