Java JFileChooser getFiles(String title, String initialRoot, String initialFile)

Here you can find the source of getFiles(String title, String initialRoot, String initialFile)

Description

get Files

License

Open Source License

Declaration

public static String[][] getFiles(String title, String initialRoot,
            String initialFile) 

Method Source Code

//package com.java2s;
/*----------------------------------------------------------------------------- 
 * vlsSMLM Software/*w ww  .j a  va  2  s . co  m*/
 * 
 * Copyright (C) 2014 Matthieu Palayret
 * Department of Chemistry
 * University of Cambridge, UK
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *---------------------------------------------------------------------------*/

import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;

public class Main {
    public static String[][] getFiles(String title, String initialRoot,
            String initialFile) {
        if (title == null || title == "")
            title = "Choose files";
        if (initialRoot == null || initialRoot == "")
            initialRoot = "E:\\Data";

        JFileChooser chooser = new JFileChooser();
        chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        FileNameExtensionFilter filter = new FileNameExtensionFilter(
                "Tiff files", "tif", "tiff");
        chooser.setFileFilter(filter);
        chooser.setDialogTitle(title);
        chooser.setCurrentDirectory(new File(initialRoot));
        chooser.setMultiSelectionEnabled(true);

        int returnVal = chooser.showOpenDialog(null);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            String[][] files = new String[chooser.getSelectedFiles().length][2];
            for (int i = 0; i < files.length; i++) {
                files[i][0] = chooser.getSelectedFiles()[i].getParent();
                files[i][1] = chooser.getSelectedFiles()[i].getName();
            }
            return files;
        } else
            return null;
    }
}

Related

  1. getFileFromChooserSave()
  2. getFileName(Component parent)
  3. getFileOrDir(String startName, boolean fileSelect)
  4. getFilePath()
  5. getFilePath(Component parent, JFileChooser fileChooser, String title, FileFilter filter)
  6. getFilesToOpen(File startDirectory, Component parent, String... filters)
  7. getFileToSave(String description, String extension, Component component)
  8. getFileWithExtension(JFileChooser c)
  9. getFixedFileChooser(File file)