APIdia Launch Partner
Top Description Fields Constructors Methods
javax.swing.filechooser

public final Class FileNameExtensionFilter

extends FileFilter
Class Inheritance
Imports
java.io.File, java.util.Locale

An implementation of FileFilter that filters using a specified set of extensions. The extension for a file is the portion of the file name after the last ".". Files whose name does not contain a "." have no file name extension. File name extension comparisons are case insensitive.

The following example creates a FileNameExtensionFilter that will show jpg files:

FileFilter filter = new FileNameExtensionFilter("JPEG file", "jpg", "jpeg");
JFileChooser fileChooser = ...;
fileChooser.addChoosableFileFilter(filter);
Since
1.6
See Also
FileFilter, javax.swing.JFileChooser#setFileFilter, javax.swing.JFileChooser#addChoosableFileFilter, javax.swing.JFileChooser#getFileFilter

Field Summary

Modifier and TypeField and Description
private final String
private final String[]
private final String[]

Constructor Summary

AccessConstructor and Description
public
FileNameExtensionFilter(String
textual description for the filter, may be null
description
,
String...
the accepted file name extensions
extensions
)

Creates a FileNameExtensionFilter with the specified description and file name extensions.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the file is to be accepted, false otherwise
accept
(File
the File to test
f
)

Implements abstract javax.swing.filechooser.FileFilter.accept.

Tests the specified file, returning true if the file is accepted, false otherwise.

public String

Returns:

the description of this filter
getDescription
()

Implements abstract javax.swing.filechooser.FileFilter.getDescription.

The description of this filter.

public String[]

Returns:

the set of file name extensions files are tested against
getExtensions
()

Returns the set of file name extensions files are tested against.

public String

Returns:

a string representation of this FileNameExtensionFilter
toString
()

Overrides java.lang.Object.toString.

Returns a string representation of the FileNameExtensionFilter.

Field Detail

descriptionback to summary
private final String description
extensionsback to summary
private final String[] extensions
lowerCaseExtensionsback to summary
private final String[] lowerCaseExtensions

Constructor Detail

FileNameExtensionFilterback to summary
public FileNameExtensionFilter(String description, String... extensions)

Creates a FileNameExtensionFilter with the specified description and file name extensions. The returned FileNameExtensionFilter will accept all directories and any file with a file name extension contained in extensions.

Parameters
description:String

textual description for the filter, may be null

extensions:String[]

the accepted file name extensions

Exceptions
IllegalArgumentException:
if extensions is null, empty, contains null, or contains an empty string
See Also
accept

Method Detail

acceptback to summary
public boolean accept(File f)

Implements abstract javax.swing.filechooser.FileFilter.accept.

Tests the specified file, returning true if the file is accepted, false otherwise. True is returned if the extension matches one of the file name extensions of this FileFilter, or the file is a directory.

Parameters
f:File

the File to test

Returns:boolean

true if the file is to be accepted, false otherwise

getDescriptionback to summary
public String getDescription()

Implements abstract javax.swing.filechooser.FileFilter.getDescription.

The description of this filter. For example: "JPG and GIF Images."

Returns:String

the description of this filter

getExtensionsback to summary
public String[] getExtensions()

Returns the set of file name extensions files are tested against.

Returns:String[]

the set of file name extensions files are tested against

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation of the FileNameExtensionFilter. This method is intended to be used for debugging purposes, and the content and format of the returned string may vary between implementations.

Returns:String

a string representation of this FileNameExtensionFilter