Java JFileChooser PromptForFileOpen(Component c)

Here you can find the source of PromptForFileOpen(Component c)

Description

Prompt For File Open

License

Open Source License

Declaration

public static String PromptForFileOpen(Component c) 

Method Source Code


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

import java.awt.Component;
import java.io.File;
import javax.swing.JFileChooser;

public class Main {
    public static String PromptForFileOpen(Component c) {
        JFileChooser fc = new JFileChooser();
        //ModuleFileTools.DPMSynthFilter filter = new ModuleFileTools.DPMSynthFilter();
        fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        fc.setCurrentDirectory(new File(".//Patches//"));
        //fc.setFileFilter(filter);
        int returnVal = fc.showOpenDialog(c);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            return fc.getCurrentDirectory() + "\\" + file.getName();
        } else {/*w w w  .j  a  v a 2  s .c om*/
            return null;
        }
    }
}

Related

  1. openDataFileChooser(Component com)
  2. openFile()
  3. openFile(String fileExtension)
  4. promptFile(File file, FileFilter filter, String title)
  5. promptForFilename(String title)
  6. promptSaveJFileChooser(String suggestedFileName, FileNameExtensionFilter... fileNameExtensionFilters)
  7. readAsString(File file)
  8. readAsString(File file)
  9. readFromFile()