Here you can find the source of getFileFilterForExtensions(final String[] exts, final boolean ignoreCase)
public static FileFilter getFileFilterForExtensions(final String[] exts, final boolean ignoreCase)
//package com.java2s; /********************************************************************************************** * * Asprise OCR Java API//from ww w . j a v a 2 s .c o m * Copyright (C) 1998-2015. Asprise Inc. <asprise.com> * * This file is licensed under the GNU Affero General Public License version 3 as published by * the Free Software Foundation. * * Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language governing permissions * and limitations under the License. * * You should have received a copy of the GNU Affero General Public License. If not, please * visit <http://www.gnu.org/licenses/agpl-3.0.html>. * **********************************************************************************************/ import javax.swing.filechooser.FileFilter; import java.io.File; public class Main { public static FileFilter getFileFilterForExtensions(final String[] exts, final boolean ignoreCase) { FileFilter filter = new FileFilter() { @Override public String getDescription() { StringBuilder sb = new StringBuilder(); for (int i = 0; i < exts.length; i++) { if (i != 0) { sb.append(", "); } sb.append("*." + exts[i]); } return sb.toString(); } @Override public boolean accept(File f) { if (f == null) { return false; } if (f.isDirectory()) { return true; } else if (ignoreCase) { for (int i = 0; i < exts.length; i++) { if (f.getName().toUpperCase().endsWith("." + exts[i].toUpperCase())) { return true; } } } else { for (int i = 0; i < exts.length; i++) { if (f.getName().endsWith("." + exts[i])) { return true; } } } return false; } }; return filter; } }