Here you can find the source of getJFileChooser(String title, File initialDirectory, File initialFile, final FilenameFilter filter, int directoryMode)
Parameter | Description |
---|---|
title | a parameter |
initialDirectory | a parameter |
initialFile | a parameter |
filter | a parameter |
directoryMode | either JFileChooser.DIRECTORIES_ONLY, JFileChooser.FILES_ONLY, or JFileChooser.DIRECTORIES_ONLY : JFileChooser.FILES_AND_DIRECTORIES |
private static JFileChooser getJFileChooser(String title, File initialDirectory, File initialFile, final FilenameFilter filter, int directoryMode)
//package com.java2s; /*/*from ww w.java 2 s . co m*/ * Copyright (c) 2007-2013 The Broad Institute, Inc. * SOFTWARE COPYRIGHT NOTICE * This software and its documentation are the copyright of the Broad Institute, Inc. All rights are reserved. * * This software is supplied without any warranty or guaranteed support whatsoever. The Broad Institute is not responsible for its use, misuse, or functionality. * * This software is licensed under the terms of the GNU Lesser General Public License (LGPL), * Version 2.1 which is available at http://www.opensource.org/licenses/lgpl-2.1.php. */ import javax.swing.*; import javax.swing.filechooser.FileFilter; import java.io.File; import java.io.FilenameFilter; public class Main { /** * @param title * @param initialDirectory * @param initialFile * @param filter * @param directoryMode either JFileChooser.DIRECTORIES_ONLY, JFileChooser.FILES_ONLY, or * JFileChooser.DIRECTORIES_ONLY : JFileChooser.FILES_AND_DIRECTORIES * @return */ private static JFileChooser getJFileChooser(String title, File initialDirectory, File initialFile, final FilenameFilter filter, int directoryMode) { JFileChooser fileChooser = new JFileChooser(); if (initialDirectory != null) { fileChooser.setCurrentDirectory(initialDirectory); } if (initialFile != null) { fileChooser.setSelectedFile(initialFile); } if (filter != null) { fileChooser.setFileFilter(new FileFilter() { @Override public boolean accept(File file) { return filter.accept(file.getParentFile(), file.getName()); } @Override public String getDescription() { return ""; } }); } fileChooser.setDialogTitle(title); fileChooser.setFileSelectionMode(directoryMode); return fileChooser; } }