Java JFileChooser getFileFromChooserForPNG()

Here you can find the source of getFileFromChooserForPNG()

Description

get File From Chooser For PNG

License

Open Source License

Declaration

public static File getFileFromChooserForPNG() 

Method Source Code

//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;
    }
}

Related

  1. getFileChooser()
  2. getFileChooser()
  3. getFileChooser()
  4. getFileChooser(Component parent, JFileChooser fileChooser, JComponent accessory)
  5. getFileChooserSelectedFile(JFileChooser fchooser, boolean directoryOnly, String fileName)
  6. getFileFromChooserSave()
  7. getFileName(Component parent)
  8. getFileOrDir(String startName, boolean fileSelect)
  9. getFilePath()