Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

Create Custom Filters For JFileChooser!!!!

Thu Jun 28, 2007 5:45 am

Code for File Filters in JFileChooser and how to use File Chooser in java:
-----------------------------------------

This code, will create a file filter for you, you must only edit two areas. You will recognize which ones immediately. I will point it out nonetheless.
After creating one or two or as many filters as you want, you can run your JFileChooser, either OpenDialog or SaveDialog, and you will have filters.

java code
import javax.swing.filechooser.FileFilter;
loadPub.addChoosableFileFilter(new FileFilter() //adds new filter into list
{
String description = "Publisher Files (*.pbb)";
/*change text within "" to text you want to appear in File Chooser*/

String extension = "pbb";
/*change text within "" for Filter you want created*/
public String getDescription()
{
return description;
}
public boolean accept(File f)
{
if(f == null) return false;
if(f.isDirectory()) return true;
return f.getName().toLowerCase().endsWith(extension);
}
});



Remember, if you want more than one filter, simply duplicate the above code, but changing the text within the " " to the new desired filter. If for any reason this code is altered, please notify me, or place a comment about it being altered and why.



Post a reply
  Related Posts  to : Create Custom Filters For JFileChooser!!!!
 Create a Custom Log in java     -  
 Create Custom Brushes in Photoshop     -  
 How to Load Files using JFileChooser!!     -  
 Using Filters Effects     -  
 stream get filters     -  
 image processing filters project     -  
 custom cursor in javascript     -  
 Image Custom Filter In Java     -  
 dynamically load a custom user control with a param construc     -  
 Image-Viewer-Image Processing-Filters-Noise-enhancements     -  

Topic Tags

Java Swing