United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4218431 : JFileChooser does not support multi-file selection

Details
Type:
Bug
Submit Date:
1999-03-09
Status:
Resolved
Updated Date:
1999-07-15
Project Name:
JDK
Resolved Date:
1999-07-15
Component:
client-libs
OS:
solaris_2.6,solaris_2.5.1,generic
Sub-Component:
javax.swing
CPU:
sparc,generic
Priority:
P1
Resolution:
Fixed
Affected Versions:
1.1.2,1.1.6,1.2.0
Fixed Versions:
1.3.0 (beta)

Related Reports
Duplicate:
Relates:
Relates:

Sub Tasks

Description
I'm using JDK 1.2 so I think that implies I'm also using Swing 1.2.

The setMultiSelectionEnabled() method on JFileChooser is documented as
not being implemented yet.  Therefore, the call getSelectedFiles() will
never return anything.  Not being implemented is the bug.  Providing API
calls and not implementing them makes the lack of implementation a bug
(not an RFE as bugid 4102455 suggests).

<FLAME>
It is still difficult to write an acceptable file-oriented application
in Java.  In JDK 1.1, the file chooser gave us unimplemented calls for
setting filters, making it impossible to narrow the choice of files for
the user.  JDK 1.1 also did not provide a directory chooser or provide
multiple selection.  Swing has made progress and now provides filters
and directory choosing, but still no way to select multiple files.
Another notable omission for file-oriented applications is a print dialog.
These are requirements if the goal is for the Java platform to compete
with Windows.
</FLAME>

Java WorkShop 3.0 Community Edition was recently made available via
web downloads.  Once of the first comments we received, was this one
which relates to this bug and 4218429.

From: Fred Romelfanger <###@###.###>
Subject: When adding files to the project, you should be ab
To: ###@###.###

User Name:  Fred Romelfanger
Email:      ###@###.###
Platform:   SunOS
Version: Java WorkShop 3.0 Community Edition build_19 Mar  3 1999
Java Version: 1.2

When adding files to the project, you should be able to select multiple files or
select a specific directory to include.  The file selection screen would allow me
to select multiple files, but would only add one at a time to the files for the
project.  Also when creating a new project the pull down for file type should
have an option to just specify java sources rather than all files.


Name: krT82822			Date: 05/30/99


For a long time now,  the documentation for javax.swing.JFileChooser 
says 'this feature has not yet been implemented in the current L&Fs' 
for the multiple file selection.

Please don't forget to implement it, it would be very useful!

BTW, a separate dialog for direction selection would be nice: I know JFileChooser has 
a directories-only option, but users say it's a bit confusing when used
for this purpose.
(Review ID: 54339)
======================================================================

                                    

Comments
WORK AROUND


I agree with the <FLAME> tag.
HERE is an ugly solution, but it's better than waiting for a fix from the Swing team ;-):

(from http://manning.spindoczine.com/sbe/files/uts2/Chapter14html/Chapter14.htm)

public static File[] getSelectedFiles(JFileChooser chooser) {
// Although JFileChooser won't give us this information,
// we need it...
Container c1 = (Container)chooser.getComponent(3);
JList list = null;
while (c1 != null) {
Container c = (Container)c1.getComponent(0);
if (c instanceof JList) {
list = (JList)c;
break;
}
c1 = c;
}
Object[] entries = list.getSelectedValues();
File[] files = new File[entries.length];
for (int k=0; k<entries.length; k++) {
if (entries[k] instanceof File)
files[k] = (File)entries[k];
}
return files;
}

ludovic.champenois@Eng 1999-04-15
                                     
1999-04-15
SUGGESTED FIX

Implement the API calls that are provided.  I fail to understand
the logic behind providing unimplemented calls.  

I agree with the <FLAME> tag.
HERE is an ugly solution, but it's better than waiting for a fix from the Swing team ;-):

(from http://manning.spindoczine.com/sbe/files/uts2/Chapter14html/Chapter14.htm)

public static File[] getSelectedFiles(JFileChooser chooser) {
// Although JFileChooser won't give us this information,
// we need it...
Container c1 = (Container)chooser.getComponent(3);
JList list = null;
while (c1 != null) {
Container c = (Container)c1.getComponent(0);
if (c instanceof JList) {
list = (JList)c;
break;
}
c1 = c;
}
Object[] entries = list.getSelectedValues();
File[] files = new File[entries.length];
for (int k=0; k<entries.length; k++) {
if (entries[k] instanceof File)
files[k] = (File)entries[k];
}
return files;
}

ludovic.champenois@Eng 1999-04-15
                                     
1999-04-15
EVALUATION


I agree with the <FLAME> tag.
HERE is an ugly solution, but it's better than waiting for a fix from the Swing team ;-):

(from http://manning.spindoczine.com/sbe/files/uts2/Chapter14html/Chapter14.htm)

public static File[] getSelectedFiles(JFileChooser chooser) {
// Although JFileChooser won't give us this information,
// we need it...
Container c1 = (Container)chooser.getComponent(3);
JList list = null;
while (c1 != null) {
Container c = (Container)c1.getComponent(0);
if (c instanceof JList) {
list = (JList)c;
break;
}
c1 = c;
}
Object[] entries = list.getSelectedValues();
File[] files = new File[entries.length];
for (int k=0; k<entries.length; k++) {
if (entries[k] instanceof File)
files[k] = (File)entries[k];
}
return files;
}

Ludovic
                                     
2004-06-11
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
generic

FIXED IN:
kestrel-beta

INTEGRATED IN:
kestrel-beta


                                     
2004-06-14



Hardware and Software, Engineered to Work Together