Java JFileChooser Filter createFileFilter(final String filterName, final String... extensionPatterns)

Here you can find the source of createFileFilter(final String filterName, final String... extensionPatterns)

Description

Creates file filter for files with specified extensions and filter name.

License

Open Source License

Parameter

Parameter Description
extensionPattern a parameter
filterName a parameter

Declaration

public static FileFilter createFileFilter(final String filterName, final String... extensionPatterns) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

import javax.swing.filechooser.FileFilter;

public class Main {
    /**/*from w  w  w .j av a  2  s  .  co  m*/
     * Creates file filter for files with specified extensions and filter name.
     *
     * @param extensionPattern
     * @param filterName
     * @return
     */
    public static FileFilter createFileFilter(final String filterName, final String... extensionPatterns) {
        return new FileFilter() {
            @Override
            public boolean accept(final File f) {
                if (f.isDirectory()) {
                    return true;
                }

                final String path = f.getAbsolutePath();
                for (final String extension : extensionPatterns) {
                    if (path.toLowerCase().endsWith(extension.toLowerCase())) {
                        return true;
                    }
                }
                return false;
            }

            @Override
            public String getDescription() {
                return filterName;
            }
        };
    }
}

Related

  1. completeFileExtension(File file, FileFilter filter)
  2. createFileFilter(final String description, final String[] extensions)
  3. createFileFilter(final String description, String extension)
  4. createFileFilter(final String ext, final String desc)
  5. createFileFilter(final String filter)
  6. createFileFilter(String text, String[]... suffixes)
  7. fileEndsInValidExtension(File file, FileNameExtensionFilter filter)
  8. fileNameAutoExtend(FileFilter filter, File file)
  9. getBinaryFileFilter()