-1
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";
      }
}
AJ.
  • 4,526
  • 5
  • 29
  • 41
manujindal
  • 11
  • 2

2 Answers2

1

By calling the setFileFilter method.

E.g., in your code:

JFileChooser chooser = new JFileChooser();
chooser.setFileFilter(new Myfilter());
Alexis C.
  • 91,686
  • 21
  • 171
  • 177
ebo
  • 2,717
  • 1
  • 27
  • 22
1

calling set filter may not work here , I got the better solution by below code

FileNameExtensionFilter("XML","xml","xml&XML"));
Sumit Pathak
  • 671
  • 1
  • 6
  • 25
manujindal
  • 11
  • 2