Java JFileChooser chooseFile()

Here you can find the source of chooseFile()

Description

choose File

License

Open Source License

Declaration

public static File chooseFile() 

Method Source Code

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

import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.JFrame;

import javax.swing.filechooser.FileNameExtensionFilter;

public class Main {
    public static File chooseFile() {
        JFileChooser chooser = new JFileChooser();
        File f = null;/*from w  ww .j  a v  a  2  s .  c  o  m*/
        FileNameExtensionFilter filter = new FileNameExtensionFilter("Audio Files", "wav", "mp3", "flac");
        //chooser.setFileFilter(filter);
        int returnVal = chooser.showOpenDialog(new JFrame(""));
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            f = chooser.getSelectedFile();
            System.out.println("You chose to open this file: " + f.getName());
        }
        return f;
    }
}

Related

  1. askForFolder(File rootDir)
  2. askUserForFileURL(Component aParent, boolean bOpen)
  3. browseFileForList(DefaultListModel listModel, JFileChooser fileChooser, Component parent)
  4. chooseDirectory(Component parentComponent, File directory, String title)
  5. chooseDirectory(String name, final String desc, File curdir)
  6. chooseFile()
  7. chooseFile(Component p, String message, boolean toOpen, int fileType)
  8. chooseFile(Component parent, String title, boolean open)
  9. chooseFile(Component parentComponent, String title, File curDir, String suffix)