• Post Reply Bookmark Topic Watch Topic
  • New Topic

FileChooser's FilenameFilter  RSS feed

 
Manjula Rao
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
need help on getting rid of the "All Files (*.*)" option in file type combo in the FileChooser box.
Thanx
Manjula
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think you can get rid of it, but you can extend FileFilter to replace it with something else.
public class GifFileFilter extends FileFilter
{
public boolean accept( File f )
{
return( f.getName().toLowerCase().endsWith(".gif") | | f.isDirectory() );
}
public String getDescription()
{
return( "GIF Images" );
}
}
Once created you can use it by:
yourFC.setFileFilter( new GifFileFilter() );
You can support multiple file filters with the following:
yourFC.addChoosableFileFilter( yourFC.getAcceptAllFileFilter() );
Hope this helps,
Manfred.
 
Manjula Rao
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Manfred,
thanx for the reply. i have done just that and it did not help. All files option still remains.
Manjula
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My mistake ...
If you JUST want to get rid of the pulldown choice for All Files, then you need to call the following FileChooser method:
JFileChooser y = new JFileChooser();
y.removeChoosableFileFilter( y.getAcceptAllFileFilter() );
If you have not called: setFileFilter method then you will get a pulldown menu that has no elements in it (not very useful!).
As I said before, you can't get rid of the option menu ...
Manfred.
 
Manjula Rao
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manfred
that perfectly solves my problem.
thanx
Manjula
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!