• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

FileChooser's FilenameFilter  RSS feed

 
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
 
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
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!