Java JFileChooser Filter createFileFilter(final String filter)

Here you can find the source of createFileFilter(final String filter)

Description

create File Filter

License

Open Source License

Declaration

public static FileFilter createFileFilter(final String filter) 

Method Source Code

//package com.java2s;
/*/*from   w  w  w .  jav  a2s .  c  om*/
 * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
 * All rights reserved. This program is made available under the terms of the
 * Eclipse Public License v1.0 which accompanies this distribution, and is
 * available at http://www.eclipse.org/legal/epl-v10.html
 * Contributors:
 * General Robotix Inc.
 * National Institute of Advanced Industrial Science and Technology (AIST) 
 */

import java.io.File;

import javax.swing.filechooser.FileFilter;

public class Main {
    public static FileFilter createFileFilter(final String filter) {
        return new FileFilter() {
            public boolean accept(File f) {
                String ext = "";
                String path = f.getPath();
                int idx = path.lastIndexOf('.');
                if (idx > 0) {
                    ext = path.substring(idx + 1).toLowerCase();
                    if (ext.equals(filter))
                        return true;
                }
                return f.isDirectory();
            }

            public String getDescription() {
                return filter + " files (*." + filter + ")";
            }
        };
    }
}

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 description, String extension)
  5. createFileFilter(final String ext, final String desc)
  6. createFileFilter(final String filterName, final String... extensionPatterns)
  7. createFileFilter(String text, String[]... suffixes)
  8. fileEndsInValidExtension(File file, FileNameExtensionFilter filter)
  9. fileNameAutoExtend(FileFilter filter, File file)