Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.File;

import javax.swing.JFileChooser;

import javax.swing.filechooser.FileFilter;

public class Main {
    /**
     * Devuelve un jfilechooser 
     * @return 
     */
    public static JFileChooser generateExcelFileChooser() {
        return generateFileChooser("Excel(xls,xlsx)", "xls", "xlsx");
    }

    public static JFileChooser generateFileChooser(String description, String... ext) {
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        fileChooser.setFileFilter(new FileFilter() {
            @Override
            public boolean accept(File f) {
                boolean res = f.isDirectory();
                for (String s : ext) {
                    res = res || f.getName().endsWith("." + s);
                }
                return res;
            }

            @Override
            public String getDescription() {
                return description;
            }

        });
        return fileChooser;
    }
}