[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
JavaFAQ_JFileChooserCustomFilters
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.
your import List should also have this: import javax.swing.filechooser.FileFilter;
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 anyreason this code is altered, please notify me, or place a comment about it being altered and why.
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
JavaFAQ_JFileChooserCustomFilters
Code for File Filters in JFileChooser
I do not claim that this code is mine, but I have been givin it and I will publish it under the GPL LicenseThis 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.
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);
}
});
That's it, you need only change to your needs the commented text's respective code above. Then you must import the FileFilter package.
your import List should also have this: import javax.swing.filechooser.FileFilter;
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 anyreason this code is altered, please notify me, or place a comment about it being altered and why.
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
