JDK-8013442 : No file filter selected in file type combo box when using JFileChooser
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_7
  • Submitted: 2013-04-04
  • Updated: 2014-11-17
  • Resolved: 2013-06-19
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8 b96Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
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 " );