I want to add a Filter to the JFileChooser. The filter should list down
the folders and files with the extension .xml. The problem in writing custom
filter is it lists only the .xml files only. Folders are not visible. the code i
have typed is
jfc = new JFileChooser();
jfc.addChoosableFileFilter(new MyFilter());
jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
MyFilter Class
public class MyFilter extends javax.swing.filechooser.FileFilter
{
public boolean accept(File file)
{
String filename = file.getName();
return filename.endsWith(".xml");
}
public String getDescription()
{
return "XML Files";
}
}
Can anyone help me to solve the problem? I didn't know how to list down xml
files along with the foldes.