Skip to Main Content

Java Programming

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 - File save as

807589Sep 26 2008 — edited Sep 29 2008
Hi,

I have a method in my application called "export" which exports the JPanel content into a file.
I used the JFileChooser to let the users choose their desired location for saving the file.
The problem is unless user explicitly types in the file format, it saves the file with no extension.
How can I have formats like jpg, png in the File Type drop down menu.

The code is on a different computer, so dont worry about syntax errors, I just write the important bits:
JFileChooser jfc = new JFileChooser();

int answer = jfc.showSaveDialog(this);

if(answer==jfc.APPROVE_OPTION) {

   try {
      
      File file = jfc.getSelectedFile();
      ImageIO.write(Graph, "png", file); //Graph is what that needs to be exported  

   } catch () {}
any help, highly appreciated, thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 27 2008
Added on Sep 26 2008
16 comments
1,048 views