Name: joT67522 Date: 01/07/98
Previous versions of swing had a getSelectedFiles()
method on JFileChooser. This method is gone,
leaving only getSelectedFile(). However,
the JFileChooser still allows multiple files
to be selected (a wonderful thing IMHO;),
but I have to drop into the JDirectoryPane
to get a method that returns a vector of
selected files.
Unfortunately, JDirectoryPane::getSelectedFiles()
doesn't work either, returning only the first
selected file, and no others.
---------
[second email]
First off, notice that it IGNORES all the settings for:
setLocationTitle("LocationTitle");
setTypesTitle("TypesTitle");
setOkayTitle("OkayTitle");
setCancelTitle("CancelTitle");
setPrompt("Prompt");
Second, it will put a FileChooser with your home directory
up and allow you to select files. When you press OK it
will tell you:
How many files were displayed.
How many the DirectoryPane reported as selected.
How many the ListSelectionModel reported as selected.
If you use the SHIFT modifier to select multiple files,
you'll notice that only one file is reported as selected.
This is the bug I was referring to in my original submission,
but certainly the others are important as well. For example,
I can't seem to make anything other than "Save" show up
in the frame's title bar.
Let me know if you need more info...
import java.awt.Frame;
import com.sun.java.swing.JFileChooser;
import com.sun.java.swing.ListSelectionModel;
import java.util.Vector;
public class fc
{
public static void main(String argv[])
{
Frame fcFrame = new Frame("FrameTitle");
JFileChooser fc = new JFileChooser();
fc.setLocationTitle("LocationTitle");
fc.setTypesTitle("TypesTitle");
fc.setOkayTitle("OkayTitle");
fc.setCancelTitle("CancelTitle");
fc.setPrompt("Prompt");
switch (fc.showDialog(fcFrame))
{
case 0:
Vector allFiles = fc.getDirectoryPane().getTypedFiles();
int numFiles = allFiles.size();
System.out.println("TOTAL FILES DISPLAYED = " + numFiles);
// We didn't need to get the JDirectoryPane in 0.6.1,
// as the JFileChooser had a getSelectedFiles()
// method... one which mysteriously disappeared in 0.7
int numSelFiles = fc.getDirectoryPane().
getSelectedFiles().size();
System.out.println("SELECTED FILES RETURNED = " + numSelFiles);
ListSelectionModel sel = fc.getDirectoryPane().
getListSelectionModel();
Vector selFiles = new Vector();
for (int i = 0 ; i < allFiles.size(); i++)
{
if(sel.isSelectedIndex(i))
{
selFiles.addElement(allFiles.elementAt(i));
}
}
numSelFiles = selFiles.size();
System.out.println("MANUAL COUNT PRODUCES = " + numSelFiles);
break;
default:
System.out.println("YOU DID NOT PRESS OK");
}
System.exit(0);
}
}
Andy
(Review ID: 22794)
======================================================================