add jFileChooserFilter to your java code
Hi,
Today I am going to show the way to use JFileChooser with FileNameExtensionFilter. This is very useful for building user friendly applications. FileNameExtensionFilter is used to tell which files extentions are allowed for the jFileChooser. This will make files with specific extensions appear and all other files disappear from the jfilechooser dialog.
First of all we need to create a list of the accepted extensions. This is an example:
String [] acceptedExt={“txt”,”doc”};
Then we create a FileNameExtensionFilter using this code:
FileNameExtensionFilter docFilter=new FileNameExtensionFilter(“Documents”, acceptedExtDoc);
Then we create a jFileChooser and add the filter to it:
JFileChooser jf=new JFileChooser();
jf.addChoosableFileFilter(docFilter);
finally, do not forget to show it for your users:
jf.showOpenDialog(null);
download example from here: jFileChooserExample

June 22, 2009 - 8:37 pm
thanks, this is helpful.