Filter

JFileChooser fileChooser = new JFileChooser(new File(filename));
fileChooser.addChoosableFile(new My());

// Open file dialog.
fileChooser.showOpenDialog(frame);
openFile(fileChooser.getSelectedFile());

class My extends javax.swing.filechooser.File {
    public boolean accept(File file) {
        String filename = file.getName();
        return filename.endsWith(".java");
    }
    public String getDescription() {
        return "*.java";
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.