Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JFilechooser save Dialog : add Extension with multiple Filefilter

802248Feb 11 2005 — edited Feb 14 2005
Hi

How do I add the correct extesion (ex,: .txt or .zip) If I have multiple filefilters.

Code Example:
//Create a file chooser
      JFileChooser fc = new JFileChooser();
      //Add File extensions *.txt, *.zip
      ZipFileFilter zipFilter = new ZipFileFilter();
      fc.addChoosableFileFilter(zipFilter);
      TxtFileFilter txtFilter = new TxtFileFilter();
      fc.setFileFilter(txtFilter);
      fc.setAcceptAllFileFilterUsed(false);
      
      
      int returnVal = fc.showSaveDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
          File file = fc.getSelectedFile();
        .....
       }
Where shoud I add .txt or .zip?

Regards
Suvi
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 14 2005
Added on Feb 11 2005
5 comments
487 views