Java JFileChooser Filter createFileFilter(final String description, String extension)

Here you can find the source of createFileFilter(final String description, String extension)

Description

Example usage:
 SwingUtil.createFileFilter("JEQL script (*.jql)", "jql") 

License

Open Source License

Parameter

Parameter Description
description a parameter
extension a parameter

Declaration

public static FileFilter createFileFilter(final String description, String extension) 

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 ww w .  j a  v  a 2s .  c om*/
     * 
     * Example usage:
     * <pre>
     * SwingUtil.createFileFilter("JEQL script (*.jql)", "jql")
     * </pre>
     * @param description
     * @param extension
     * @return
     */
    public static FileFilter createFileFilter(final String description, String extension) {
        final String dotExt = extension.startsWith(".") ? extension : "." + extension;
        FileFilter ff = new FileFilter() {
            public String getDescription() {
                return description;
            }

            public boolean accept(File f) {
                return f.isDirectory() || f.toString().toLowerCase().endsWith(dotExt);
            }
        };
        return ff;
    }
}

Related

  1. accept(File f, Collection filters)
  2. completeFileExtension(File file, FileFilter filter)
  3. createFileFilter(final String description, final String[] extensions)
  4. createFileFilter(final String ext, final String desc)
  5. createFileFilter(final String filter)
  6. createFileFilter(final String filterName, final String... extensionPatterns)
  7. createFileFilter(String text, String[]... suffixes)