Java JFileChooser getFileName(Component parent)

Here you can find the source of getFileName(Component parent)

Description

get file name

License

Open Source License

Declaration

public static String getFileName(Component parent) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.*;
import javax.swing.*;

public class Main {
    private static JFileChooser mFileChoose = null;

    /**/*ww w .jav a 2s .c o  m*/
     * get file name
     */
    public static String getFileName(Component parent) {

        if (mFileChoose == null) {
            mFileChoose = new JFileChooser();
            mFileChoose.setFileSelectionMode(JFileChooser.FILES_ONLY);
        }

        int returnVal = mFileChoose.showOpenDialog(parent);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            return mFileChoose.getSelectedFile().getAbsolutePath();
        } else {
            return null;
        }
    }
}

Related

  1. getFileChooser()
  2. getFileChooser(Component parent, JFileChooser fileChooser, JComponent accessory)
  3. getFileChooserSelectedFile(JFileChooser fchooser, boolean directoryOnly, String fileName)
  4. getFileFromChooserForPNG()
  5. getFileFromChooserSave()
  6. getFileOrDir(String startName, boolean fileSelect)
  7. getFilePath()
  8. getFilePath(Component parent, JFileChooser fileChooser, String title, FileFilter filter)
  9. getFiles(String title, String initialRoot, String initialFile)