Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

ExtensionFileFilter



The ExtensionFileFilter class is a file filter which is both: It allows to define a file filter which filters files depending on their extension.

For example with only one extension:
   ExtensionFileFilter filter = new ExtensionFileFilter("PNG images", "png");      

Using a vararg for the array of extensions

The ExtensionFileFilter.createFromExtensionsAndDesc(String, String...) allows to use a vararg for the array of extensions and a description.

The ExtensionFileFilter.createFromExtensions(String...) allows to use a vararg for the array of extensions and a description (the descrition will be constructed with the extensions).

For example with providing the extensions and the description of the filter:
   ExtensionFileFilter filter = ExtensionFileFilter.createFromExtensionsAndDesc("Images", "png", "jpg");     
Or with providing only the extensions (the description will be constructed automatically by using the naes of the extensions):
   ExtensionFileFilter filter = ExtensionFileFilter.createFromExtensions("png", "jpg"); // the description will be "png, jpg files"

Pattern for the extension

You can specify the extension with or without a dot at the beginning of the String. For example both ExtensionFileFilter filter = new ExtensionFileFilter("PNG images", "png") and ExtensionFileFilter filter = new ExtensionFileFilter("PNG images", ".png") will specify files with the "png" extension.

Also the extension is not case-sensitive. For example ExtensionFileFilter filter = new ExtensionFileFilter("PNG images", "PNG") specifies the same extension.

Examples

With only one extension:
   ExtensionFileFilter filter = new ExtensionFileFilter("png", "PNG images");      
With several extensions:
   String[] images = {"png", "jpg"};
   ExtensionFileFilter filter = new ExtensionFileFilter(images, "Images");      

See also


Categories: Packages | Swing

Copyright 2006-2024 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences