Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Only accept a file type in JFileChooser ?

 
Steven Zeng
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Would you please tell me how to let a JFileChooser only accept one file type for example "*.jar"(I know FileFilter). In fact, I don't want that user can select "all files" in JFileChooser, but I don't know how to disable the JCombobox.
Thanks ahead!
 
aminur rashid
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
make ur own class extenidng
javax.swing.filechooser.FileFilter

like

now add this filter to ur filechooser

Hope this will help....
 
Steven Zeng
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In fact i want that in JFileChooser user can not select "all files *.*" in file type ComBoBox. However thanks for your reply
 
Manish Hatwalne
Ranch Hand
Posts: 2591
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Steven Zeng:
In fact i want that in JFileChooser user can not select "all files *.*" in file type ComBoBox. However thanks for your reply

Use -
fileChooser.setAcceptAllFileFilterUsed(false);
HTH,
- Manish
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic