Java JFileChooser loadFile(Component parent, String title)

Here you can find the source of loadFile(Component parent, String title)

Description

This method is used to choose a file path.

License

Open Source License

Parameter

Parameter Description
parent If you want to attach it to the opener window. May be null.
title For the dialog window.

Declaration

public static java.io.File loadFile(Component parent, String title) 

Method Source Code


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

import java.awt.Component;

import javax.swing.JFileChooser;

public class Main {
    /**//from  w w  w. j a v a2 s .  c  om
     * This method is used to choose a file path.
     * @param parent If you want to attach it to the opener window. May be null.
     * @param title For the dialog window.
     * @return
     */
    public static java.io.File loadFile(Component parent, String title) {
        JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(new java.io.File("./"));
        chooser.setDialogTitle(title);
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        chooser.setVisible(true);
        if (chooser.showOpenDialog(chooser) == JFileChooser.APPROVE_OPTION) {
            return chooser.getSelectedFile();
        }
        return null;
    }
}

Related

  1. getXmlFileChooser()
  2. importFile(JFileChooser jFileChooser)
  3. initFileChooser(JFileChooser fileChooser, FileFilter filter)
  4. isDriveTraversable(File drive)
  5. loadFile()
  6. loadFileAs(Class clazz, String json)
  7. makeFileChooser()
  8. openDataFileChooser(Component com)
  9. openFile()