Java JFileChooser Filter newFileFilter(final String desc, final String[] allowed_extensions)

Here you can find the source of newFileFilter(final String desc, final String[] allowed_extensions)

Description

new File Filter

License

Open Source License

Declaration

private static javax.swing.filechooser.FileFilter newFileFilter(final String desc,
            final String[] allowed_extensions) 

Method Source Code

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

public class Main {
    private static javax.swing.filechooser.FileFilter newFileFilter(final String desc,
            final String[] allowed_extensions) {
        return new javax.swing.filechooser.FileFilter() {
            @Override/*w w  w .  j  av  a 2 s.c  om*/
            public boolean accept(java.io.File f) {
                if (f.isDirectory()) {
                    return true;
                }
                int pos = f.getName().lastIndexOf('.');
                if (pos == -1) {
                    return false;
                } else {
                    String extension = f.getName().substring(pos + 1);
                    for (String allowed_extension : allowed_extensions) {
                        if (extension.equalsIgnoreCase(allowed_extension)) {
                            return true;
                        }
                    }
                    return false;
                }
            }

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

Related

  1. list(ArrayList list, File file, javax.swing.filechooser.FileFilter filter)
  2. listAll(File file, javax.swing.filechooser.FileFilter filter)
  3. listAll(File file, javax.swing.filechooser.FileFilter filter)
  4. makeFileFilter(final String desc, final String... types)
  5. makeFileNameExtensionFilter(String[] extensions)
  6. validateFileName(final File file, final javax.swing.filechooser.FileFilter filter)
  7. wrapFilter(final javax.swing.filechooser.FileFilter filter)