Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

FileChooser's FilenameFilter

 
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
 
Been there. Done that. Went back for more. But this time, I took this tiny ad with me:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic