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

JFileChooser.getSelectedFiles() failed with multi-selection and double-click

XMLWordPrintable

    • b15
    • x86
    • linux



      Name: jk109818 Date: 03/18/2003


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

      Also java v.1.4.1_02 on Windows 2000SP3; java v.1.3.1 (Blackdown-1.3.1-02b_FCS) on Yellow Dog Linux 2.3; and an additional environment, java v.1.3.1_07, on Red Hat Linux 8.0.

      FULL OS VERSION :
      Red Hat Linux 8.0, kernel 2.4.20,
      Yellow Dog Linux 2.3, kernel 2.4.20,
      Microsoft Window 2000SP3

      A DESCRIPTION OF THE PROBLEM :
      In a JFileChooser, a file cannot be chosen again by a double-click after opening the dialog, choosing it so the dialog closes, enabling file multi-selection on the dialog, and reopening it. The array from File[] getSelectedFiles() has length 0. File getSelectedFile(), however, does retrieve the double-clicked file.

      Each of the following avoid the problem and return an array of length 1.
      -Using the accept button instead of double-clicking
      -Changing and returning to the same directory
      -Highlighting another file before switching back to the original file

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Open a JFileChooser dialog
      2) Choose a file, whether by double-click, typing and pressing enter, or selecting/typing and pressing on the accept (eg "Open") button
      3) Enable the dialog's multi-selection
      4) Reopen the dialog
      5) Choose the same file by double-click, without first choosing any other file or switching directories

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      File[] getSelectedFiles() should return an array of length 1 and contain a file object of the chosen file.
      File[] getSelectedFiles() returns an array of length 0. File getSelectedFile(), however, returns the file object.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import java.io.*;

      public class JFileChooserTest {

          public static void main(String[] args) {
      JFileChooser chooser = new JFileChooser();
      chooser.showOpenDialog(null);
      chooser.setMultiSelectionEnabled(true);
      chooser.showOpenDialog(null);
      File[] files = chooser.getSelectedFiles();
      File file = chooser.getSelectedFile();
      System.out.print("Num of files: " + files.length
      + ", file path: " + file.getPath());
          }

      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Instead of simply using:
      setMultiSelectionEnabled(true);

      Use:
      setMultiSelectionEnabled(true);
      setMultiSelectionEnabled(false);
      setMultiSelectionEnabled(true);
      (Review ID: 182336)
      ======================================================================

            tr Tejesh R
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: