Java JFileChooser Filter createFileFilter(final String description, final String[] extensions)

Here you can find the source of createFileFilter(final String description, final String[] extensions)

Description

create File Filter

License

Open Source License

Declaration

public static FileFilter createFileFilter(final String description, final String[] extensions) 

Method Source Code


//package com.java2s;

import java.io.File;

import javax.swing.filechooser.FileFilter;

public class Main {
    public static FileFilter createFileFilter(final String description, final String[] extensions) {
        return new FileFilter() {

            @Override//from  www .  j  a va  2  s. com
            public String getDescription() {
                return description;
            }

            @Override
            public boolean accept(File f) {
                if (!f.canRead())
                    return false;
                if (f.isDirectory())
                    return true;

                String name = f.getName().toLowerCase();
                for (String extension : extensions)
                    if (name.endsWith("." + extension.toLowerCase()))
                        return true;

                return false;
            }
        };
    }
}

Related

  1. accept(File f, Collection filters)
  2. completeFileExtension(File file, FileFilter filter)
  3. createFileFilter(final String description, String extension)
  4. createFileFilter(final String ext, final String desc)
  5. createFileFilter(final String filter)
  6. createFileFilter(final String filterName, final String... extensionPatterns)