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

No file filter selected in file type combo box when using JFileChooser

XMLWordPrintable

    • b96
    • windows_7

      FULL PRODUCT VERSION :
      java version " 1.7.0_07 "
      Java(TM) SE Runtime Environment (build 1.7.0_07-b10)
      Java HotSpot(TM) 64-Bit Server VM (build 23.3-b01, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      When using the javax.swing.JFileChooser a call to the method setAcceptAllFileFilterUsed(false) before showing the file chooser will select a " blank " filter in thefile type combo box. Once a custom filter has been chosen, the " blank " filter cannot be selected again.

      Note that the issue was not present in the JDK6u35.

      REGRESSION. Last worked in version 6u31

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and execute this code:

      // This was working 'as is' on JDK6u35
      JFileChooser jfc = new JFileChooser();
      jfc.resetChoosableFileFilters();
      jfc.addChoosableFileFilter(new FileFilter() {

      @Override
      public String getDescription () {
      return " Text file " ;
      }

      @Override
      public boolean accept (File f) {
      return f != null && (!f.isFile() || f.getName().endsWith( " .txt " ));
      }
      });
      jfc.setAcceptAllFileFilterUsed(false);
      jfc.showDialog(null, " Select " );

      Note the selected value of the combo box for file type.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The file chooser show only one type of file available ( " Text file " ) and is seleted when the file chooser is shown.
      ACTUAL -
      The selected filter is blank, but when selecting the added filter, the blank filter cannot be selected anymore.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      No log.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      // This was working 'as is' on JDK6u35
      JFileChooser jfc = new JFileChooser();
      jfc.resetChoosableFileFilters();
      jfc.addChoosableFileFilter(new FileFilter() {

      @Override
      public String getDescription () {
      return " Text file " ;
      }

      @Override
      public boolean accept (File f) {
      return f != null && (!f.isFile() || f.getName().endsWith( " .txt " ));
      }
      });
      jfc.setAcceptAllFileFilterUsed(false);
      jfc.showDialog(null, " Select " );
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      // Works on JDK6 & JDK7
      JFileChooser jfc = new JFileChooser();
      jfc.resetChoosableFileFilters();
      jfc.setAcceptAllFileFilterUsed(false);
      jfc.addChoosableFileFilter(new FileFilter() {

      @Override
      public String getDescription () {
      return " Text file " ;
      }

      @Override
      public boolean accept (File f) {
      return f != null && (!f.isFile() || f.getName().endsWith( " .txt " ));
      }
      });
      jfc.showDialog(null, " Select " );

            malenkov Sergey Malenkov (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: