Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Save Dialog with Choosable File Types

 
Jeff Gent
Ranch Hand
Posts: 44
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20532
54
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Jeff Gent
Ranch Hand
Posts: 44
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob! That got me where I needed to be.
 
Rob Spoor
Sheriff
Pie
Posts: 20532
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic