JDK-4193195 : multiple selection in JFileChooser using JDK1.2Rc2 doesn't work
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 1998-11-26
  • Updated: 1999-01-14
  • Resolved: 1999-01-14
Related Reports
Duplicate :  
Description

Name: clC74495			Date: 11/26/98


1) create a file dialog box
2) setMultiSelection(true);
3) if you get APPROVE_OPTION, call getSelectedFiles().
4) notice that getSelectedFiles() always returns an empty list.

import javax.swing.*;
import java.awt.event.*;
import java.awt.Component;
import java.io.File;

public class FileChooser extends JFrame implements ActionListener {

public static void main(String args[]) {
    FileChooser fc = new FileChooser();

    fc.pack();
    fc.show();
}

public FileChooser() {

    JButton b = new JButton("Press for file dialog");
    b.addActionListener(this);
    getContentPane().add(b);
}

public void actionPerformed(ActionEvent e) {
    JFileChooser chooser = new JFileChooser();
    chooser.setMultiSelectionEnabled(true);
    //chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    if (chooser.showDialog((Component)e.getSource(),
"Ok")==JFileChooser.APPROVE_OPTION) {
        File[] files = chooser.getSelectedFiles();
        System.out.println("Number of selected files: " + files.length);
    }
}

}
(Review ID: 43420)
======================================================================