Package com.sun.demo
Class ExampleFileFilter
java.lang.Object
javax.swing.filechooser.FileFilter
com.sun.demo.ExampleFileFilter
A convenience implementation of FileFilter that filters out
all files except for those type extensions that it knows about.
Extensions are of the type ".foo", which is typically found on
Windows and Unix boxes, but not on Macinthosh. Case is ignored.
Example - create a new filter that filerts out all files
but gif and jpg image files:
JFileChooser chooser = new JFileChooser();
ExampleFileFilter filter = new ExampleFileFilter(
new String{"gif", "jpg"}, "JPEG & GIF Images")
chooser.addChoosableFileFilter(filter);
chooser.showOpenDialog(this);
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a file filter.ExampleFileFilter
(String extension) Creates a file filter that accepts files with the given extension.ExampleFileFilter
(String[] filters) Creates a file filter from the given string array.ExampleFileFilter
(String[] filters, String description) Creates a file filter from the given string array and description.ExampleFileFilter
(String extension, String description) Creates a file filter that accepts the given file type. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Return true if this file should be shown in the directory pane, false if it shouldn't.void
addExtension
(String extension) Adds a filetype "dot" extension to filter against.Returns the human readable description of this filter.getExtension
(File f) Return the extension portion of the file's name .boolean
Returns whether the extension list (.jpg, .gif, etc) should show up in the human readable description.void
setDescription
(String description) Sets the human readable description of this filter.void
setExtensionListInDescription
(boolean b) Determines whether the extension list (.jpg, .gif, etc) should show up in the human readable description.
-
Constructor Details
-
ExampleFileFilter
public ExampleFileFilter()Creates a file filter. If no filters are added, then all files are accepted.- See Also:
-
ExampleFileFilter
Creates a file filter that accepts files with the given extension. Example: new ExampleFileFilter("jpg");- See Also:
-
ExampleFileFilter
Creates a file filter that accepts the given file type. Example: new ExampleFileFilter("jpg", "JPEG Image Images"); Note that the "." before the extension is not needed. If provided, it will be ignored.- See Also:
-
ExampleFileFilter
Creates a file filter from the given string array. Example: new ExampleFileFilter(String {"gif", "jpg"}); Note that the "." before the extension is not needed adn will be ignored.- See Also:
-
ExampleFileFilter
Creates a file filter from the given string array and description. Example: new ExampleFileFilter(String {"gif", "jpg"}, "Gif and JPG Images"); Note that the "." before the extension is not needed and will be ignored.- See Also:
-
-
Method Details
-
accept
Return true if this file should be shown in the directory pane, false if it shouldn't. Files that begin with "." are ignored.- Specified by:
accept
in classFileFilter
- See Also:
-
getExtension(java.io.File)
FileFilter#accepts
-
getExtension
Return the extension portion of the file's name . -
addExtension
Adds a filetype "dot" extension to filter against. For example: the following code will create a filter that filters out all files except those that end in ".jpg" and ".tif": ExampleFileFilter filter = new ExampleFileFilter(); filter.addExtension("jpg"); filter.addExtension("tif"); Note that the "." before the extension is not needed and will be ignored. -
getDescription
Returns the human readable description of this filter. For example: "JPEG and GIF Image Files (*.jpg, *.gif)"- Specified by:
getDescription
in classFileFilter
- See Also:
-
setDescription
Sets the human readable description of this filter. For example: filter.setDescription("Gif and JPG Images"); -
setExtensionListInDescription
public void setExtensionListInDescription(boolean b) Determines whether the extension list (.jpg, .gif, etc) should show up in the human readable description. Only relevent if a description was provided in the constructor or using setDescription(); -
isExtensionListInDescription
public boolean isExtensionListInDescription()Returns whether the extension list (.jpg, .gif, etc) should show up in the human readable description. Only relevent if a description was provided in the constructor or using setDescription();
-