Java Utililty Methods JFileChooser

List of utility methods to do JFileChooser

Description

The list of methods to do JFileChooser are organized into topic(s).

Method

StringopenFile()
open File
JFileChooser fc = null;
fc = new JFileChooser(System.getProperty("user.home"));
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnVal = fc.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
    File file = fc.getSelectedFile();
    if (file.getPath().equals(""))
        return null;
...
StringopenFile(String fileExtension)
open File
JFileChooser dlgFile = new JFileChooser();
dlgFile.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
dlgFile.setApproveButtonText("Open");
int returnVal = dlgFile.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
    File file = dlgFile.getSelectedFile();
    return file.getAbsolutePath();
return "";
FilepromptFile(File file, FileFilter filter, String title)
Checks if the specified file exists.
if (file == null || !file.exists()) {
    File start = file.getParentFile();
    if (!start.exists()) {
        start = new File(".");
    JFileChooser chooser = new JFileChooser(start);
    if (title != null) {
        chooser.setDialogTitle(title);
...
FilepromptForFilename(String title)
Display the showSaveDialog which allows the user to specify file and directory
File file = null;
String _title = "Arrah Technology Save File";
if (title != null || "".equals(title) == false)
    _title = title;
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle(_title);
chooser.setCurrentDirectory(new File("."));
int returnVal = chooser.showSaveDialog(null);
...
StringPromptForFileOpen(Component c)
Prompt For File Open
JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
fc.setCurrentDirectory(new File(".//Patches//"));
int returnVal = fc.showOpenDialog(c);
if (returnVal == JFileChooser.APPROVE_OPTION) {
    File file = fc.getSelectedFile();
    return fc.getCurrentDirectory() + "\\" + file.getName();
} else {
...
FilepromptSaveJFileChooser(String suggestedFileName, FileNameExtensionFilter... fileNameExtensionFilters)
prompt Save J File Chooser
return null;
StringreadAsString(File file)
read As String
return readAsString(file.toPath());
StringreadAsString(File file)
read As String
return readAsString(file.toPath());
double[][]readFromFile()
read matrix written as atext file with ; split token
return readFromFile(getFileFromChooserLoad(getDefaultDirectory()).getAbsolutePath(), ";");
voidremoveChoosableFileFilters(JFileChooser fc)
remove Choosable File Filters
FileFilter[] filters = fc.getChoosableFileFilters();
for (int i = 0; i < filters.length; i++) {
    fc.removeChoosableFileFilter(filters[i]);
return;