Here you can find the source of getFileFromChooserForPNG()
public static File getFileFromChooserForPNG()
//package com.java2s; //License from project: Open Source License import java.io.*; import javax.swing.JFileChooser; import javax.swing.filechooser.FileNameExtensionFilter; public class Main { public static File getFileFromChooserForPNG() { JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("save panel as a png file"); chooser.setSize(new java.awt.Dimension(45, 37)); // Generated chooser.setFileFilter(new FileNameExtensionFilter("png", "png")); File file = new File("C:\\deneme.png"); if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); if (file.getName().indexOf(".png") == -1) { File file2 = new File(file.getParent() + "\\" + file.getName() + ".png"); file = file2;/*from w w w . j a v a2s.com*/ } return file; } return null; } }