24 Sept 2012

Filter File Type with FileDialog in java

/* Filter File Type with FileDialog in java */
public void actionPerformed(ActionEvent e) 
        {
            FileDialog saveFileDialog = new FileDialog(new Frame(), "Save", FileDialog.SAVE);
            saveFileDialog.setFilenameFilter(new FilenameFilter()
            {
                public boolean accept(File dir, String name)
              {
                    return name.endsWith(".jpg") || name.endsWith(".jpeg");
                }
            });
            saveFileDialog.setFile("Untitled.jpg");
            saveFileDialog.setVisible(true);
        }

or use

saveFileDialog.setFile("*.jpg");