Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!