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

JFileChooser.setAcceptAllFileFilterUsed changes currently active filter

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.3.0
    • docs
    • beta
    • generic
    • generic



      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)
      ======================================================================

            sharonz Sharon Zakhour (Inactive)
            ssultanasunw Shaheen Sultana (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: