Java JFileChooser getFilesToOpen(File startDirectory, Component parent, String... filters)

Here you can find the source of getFilesToOpen(File startDirectory, Component parent, String... filters)

Description

get Files To Open

License

Open Source License

Declaration

public static File[] getFilesToOpen(File startDirectory, Component parent, String... filters) 

Method Source Code


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

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

public class Main {
    public static File[] getFilesToOpen(File startDirectory, Component parent, String... filters) {
        JFileChooser chooser = new JFileChooser(startDirectory);
        FileNameExtensionFilter filter = new FileNameExtensionFilter("Soubory " + toString(filters), filters);
        chooser.setFileFilter(filter);//from  w w  w.  j  av a  2s.c o  m
        chooser.setMultiSelectionEnabled(true);
        int returnValue = chooser.showOpenDialog(parent);
        if (returnValue == JFileChooser.APPROVE_OPTION) {
            return chooser.getSelectedFiles();
        }

        return new File[0];
    }

    private static String toString(String[] filters) {
        StringBuilder sb = new StringBuilder();
        sb.append(filters[0]);
        for (int i = 1; i < filters.length; i++) {
            sb.append(", ").append(filters[1]);
        }
        return sb.toString();
    }
}

Related

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