public final class FileFilterExtensions extends FileFilter implements INameFilter
Configureable implementation of FileFilter
that filters files by their extension (e.g.: ".txt").
The extension Strings are provided to the constructor (no configuration of initialized instance provided yet) and have to be the sole extension without the dot.
This class is most often used to configure JFileChooser
dialogs. Therefore it accepts all directories to allow browsing.
...
JFileChooser fileChooser = new JFileChooser();
FileFilter soundFileFilter = new FileFilterExtensions(new String[]{"wav","mp3"});
fileChooser.setFileFilter(soundFileFilter);
...
Constructor and Description |
---|
FileFilterExtensions(String[] extensionsWithoutDot)
Creates an instance that will accept files with the given extensions.
|
Modifier and Type | Method and Description |
---|---|
boolean |
accept(File pathname) |
boolean |
accept(String urlstring)
Accept the file denoted by the given url String.
|
String |
getDescription() |
public FileFilterExtensions(String[] extensionsWithoutDot) throws IllegalArgumentException
extensionsWithoutDot
- A String[] containing extension strings without the dot like:
new String[]{"bat","txt","dict"}
IllegalArgumentException
- if the given extensions are inivalid.public boolean accept(File pathname)
accept
in class FileFilter
FileFilter.accept(java.io.File)
public boolean accept(String urlstring)
INameFilter
accept
in interface INameFilter
urlstring
- a String in url format denoting a file.INameFilter.accept(String)
public String getDescription()
getDescription
in class FileFilter
FileFilter.getDescription()
Copyright © 2019. All rights reserved.