Name: ssT124754 Date: 02/06/2001
~/project/test>java -version
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
When calling setAcceptAllFileFilterUsed(true) in a JFileChooser, the current
used filter switches to the acceptallfilter, but this behaviour is not
documented.
This is illustrated in the example below (exchanging line 1 & 2 changes the
behaviour of the program).
Suggested fix:
- Document this fact
- Change behaviour
import javax.swing.*;
import java.io.*;
public class Test {
public static void main(String args[]) {
JFileChooser fileChooser = new JFileChooser();
javax.swing.filechooser.FileFilter filter = new FooFilter();
fileChooser.addChoosableFileFilter(filter);
fileChooser.setAcceptAllFileFilterUsed(true); // line 1
fileChooser.setFileFilter(filter); // line 2
// exchanging line 1 and line 2 changes behaviour
fileChooser.showOpenDialog(null);
}
}
class FooFilter extends javax.swing.filechooser.FileFilter {
public boolean accept(File f) {
return true;
}
public String getDescription() {
return "Foo Filters nothing";
}
}
(Review ID: 116473)
======================================================================