-
Bug
-
Resolution: Cannot Reproduce
-
P3
-
None
-
7u25
-
windows_7
FULL PRODUCT VERSION :
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
Add more than 2 file filters to JFileChooser, open that file chooser and scroll through available file types -> the "Files Of Type" combo box redraws incorrectly.
For example, the combo box contains:
All Files
JPG Files
GIF files
PNG files
When I move cursor down to GIF files, the list content changes to:
JPG files
JPG files
GIF files
PNG files
down to PNG files, the expanded combo box content is:
GIF files
PNG files
GIF files
PNG files
Seems the new behavior copies the actually selected file filter description to the first line of expanded combo box, but it does not work as expected.
REGRESSION. Last worked in version 7u10
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package mainclass;
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
public class MainClass {
public static void main(String[] a) {
JFileChooser fileChooser = new JFileChooser(".");
FileFilter filter1 = new ExtensionFileFilter("JPG files", new String[] {"jpg","jpeg"});
FileFilter filter2 = new ExtensionFileFilter("GIF files", new String[] {"gif"});
FileFilter filter3 = new ExtensionFileFilter("PNG files", new String[] {"png"});
fileChooser.addChoosableFileFilter(filter1);
fileChooser.addChoosableFileFilter(filter2);
fileChooser.addChoosableFileFilter(filter3);
fileChooser.setFileFilter(filter1);
int status = fileChooser.showOpenDialog(null);
if (status == JFileChooser.APPROVE_OPTION) {
File selectedFile = fileChooser.getSelectedFile();
System.out.println(selectedFile.getParent());
System.out.println(selectedFile.getName());
} else if (status == JFileChooser.CANCEL_OPTION) {
System.out.println(JFileChooser.CANCEL_OPTION);
}
}
}
class ExtensionFileFilter extends FileFilter {
String description;
String extensions[];
public ExtensionFileFilter(String description, String extension) {
this(description, new String[] { extension });
}
public ExtensionFileFilter(String description, String extensions[]) {
if (description == null) {
this.description = extensions[0];
} else {
this.description = description;
}
this.extensions = (String[]) extensions.clone();
toLower(this.extensions);
}
private void toLower(String array[]) {
for (int i = 0, n = array.length; i < n; i++) {
array[i] = array[i].toLowerCase();
}
}
@Override
public String getDescription() {
return description;
}
@Override
public boolean accept(File file) {
if (file.isDirectory()) {
return true;
} else {
String path = file.getAbsolutePath().toLowerCase();
for (int i = 0, n = extensions.length; i < n; i++) {
String extension = extensions[i];
if ((path.endsWith(extension) && (path.charAt(path.length() - extension.length() - 1)) == '.')) {
return true;
}
}
}
return false;
}
}
---------- END SOURCE ----------
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
Add more than 2 file filters to JFileChooser, open that file chooser and scroll through available file types -> the "Files Of Type" combo box redraws incorrectly.
For example, the combo box contains:
All Files
JPG Files
GIF files
PNG files
When I move cursor down to GIF files, the list content changes to:
JPG files
JPG files
GIF files
PNG files
down to PNG files, the expanded combo box content is:
GIF files
PNG files
GIF files
PNG files
Seems the new behavior copies the actually selected file filter description to the first line of expanded combo box, but it does not work as expected.
REGRESSION. Last worked in version 7u10
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package mainclass;
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
public class MainClass {
public static void main(String[] a) {
JFileChooser fileChooser = new JFileChooser(".");
FileFilter filter1 = new ExtensionFileFilter("JPG files", new String[] {"jpg","jpeg"});
FileFilter filter2 = new ExtensionFileFilter("GIF files", new String[] {"gif"});
FileFilter filter3 = new ExtensionFileFilter("PNG files", new String[] {"png"});
fileChooser.addChoosableFileFilter(filter1);
fileChooser.addChoosableFileFilter(filter2);
fileChooser.addChoosableFileFilter(filter3);
fileChooser.setFileFilter(filter1);
int status = fileChooser.showOpenDialog(null);
if (status == JFileChooser.APPROVE_OPTION) {
File selectedFile = fileChooser.getSelectedFile();
System.out.println(selectedFile.getParent());
System.out.println(selectedFile.getName());
} else if (status == JFileChooser.CANCEL_OPTION) {
System.out.println(JFileChooser.CANCEL_OPTION);
}
}
}
class ExtensionFileFilter extends FileFilter {
String description;
String extensions[];
public ExtensionFileFilter(String description, String extension) {
this(description, new String[] { extension });
}
public ExtensionFileFilter(String description, String extensions[]) {
if (description == null) {
this.description = extensions[0];
} else {
this.description = description;
}
this.extensions = (String[]) extensions.clone();
toLower(this.extensions);
}
private void toLower(String array[]) {
for (int i = 0, n = array.length; i < n; i++) {
array[i] = array[i].toLowerCase();
}
}
@Override
public String getDescription() {
return description;
}
@Override
public boolean accept(File file) {
if (file.isDirectory()) {
return true;
} else {
String path = file.getAbsolutePath().toLowerCase();
for (int i = 0, n = extensions.length; i < n; i++) {
String extension = extensions[i];
if ((path.endsWith(extension) && (path.charAt(path.length() - extension.length() - 1)) == '.')) {
return true;
}
}
}
return false;
}
}
---------- END SOURCE ----------