aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Save Dialog with Choosable File Types Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Save Dialog with Choosable File Types" Watch "Save Dialog with Choosable File Types" New topic
Author

Save Dialog with Choosable File Types

Jeff Gent
Ranch Hand

Joined: Mar 24, 2011
Posts: 44

I have a application that has multiple writers, meaning I can save the data in several formats. So I give the user the option to save a file. Many applications have the drop down of the file type you'd like to save. For example, Photoshop may allow you to save the picture as a .jpg, .png, .gif, etc. Based on the selection, the appropriate writer can be used. How can I do this in Java? Thanks!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19557
    
  16

Use a JFileChooser. You can add javax.swing.filechooser.FileFilter implementations using addChoosableFileFilter, and retrieve the currently selected one with getFileFilter(). So your code should look a bit like this:
Note that by default, there is a "select all" file filter. You can remove this using fileChooser.setAcceptAllFileFilterUsed(false).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jeff Gent
Ranch Hand

Joined: Mar 24, 2011
Posts: 44

Thanks Rob! That got me where I needed to be.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19557
    
  16

You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Save Dialog with Choosable File Types
 
Similar Threads
how can i save contents of a JEditorPane?
adding a save method
Saving a file to clients machine
save and load JPEG image from disk
How do i save a file that has been generated using JSP in excel format .