• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

FileChooser's FilenameFilter

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Manfred
that perfectly solves my problem.
thanx
Manjula
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic