本文整理汇总了Java中javax.swing.JFileChooser.getSelectedFiles方法的典型用法代码示例。如果您正苦于以下问题:Java JFileChooser.getSelectedFiles方法的具体用法?Java JFileChooser.getSelectedFiles怎么用?Java JFileChooser.getSelectedFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JFileChooser
的用法示例。
在下文中一共展示了JFileChooser.getSelectedFiles方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: browseLibraryButtonActionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void browseLibraryButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseLibraryButtonActionPerformed
JFileChooser chooser = new JFileChooser(ModuleUISettings.getDefault().getLastChosenLibraryLocation());
File[] olds = convertStringToFiles(txtLibrary.getText().trim());
chooser.setSelectedFiles(olds);
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setMultiSelectionEnabled(true);
chooser.addChoosableFileFilter(new JarZipFilter());
int ret = chooser.showDialog(this, getMessage("LBL_Select"));
if (ret == JFileChooser.APPROVE_OPTION) {
File[] files = chooser.getSelectedFiles();
if (files.length == 0) {
return;
}
String path = "";
for (int i = 0; i < files.length; i++) {
path = path + files[i] + ( i == files.length - 1 ? "" : File.pathSeparator);
}
txtLibrary.setText(path);
ModuleUISettings.getDefault().setLastChosenLibraryLocation(files[0].getParentFile().getAbsolutePath());
}
}
示例2: showFileSelection
import javax.swing.JFileChooser; //导入方法依赖的package包/类
public static List<Data> showFileSelection() throws Exception{
List<Data> ret = new ArrayList<Data>();
JFileChooser jfc = new JFileChooser();
jfc.setMultiSelectionEnabled(true);
jfc.setDialogTitle("Choose the files to sign");
SignUtils.playBeeps(1);
if(jfc.showOpenDialog(null) != JFileChooser.APPROVE_OPTION)
return null;
File[] choosedFileList = jfc.getSelectedFiles();
for(File file:choosedFileList){
String id = file.getAbsolutePath();
byte[] fileContent = IOUtils.readFile(file);
ret.add(new Data(id, fileContent));
}
return ret;
}
示例3: addOutputActionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void addOutputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addOutputActionPerformed
JFileChooser chooser = new JFileChooser();
FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
chooser.setFileSelectionMode (JFileChooser.FILES_AND_DIRECTORIES);
chooser.setMultiSelectionEnabled(true);
if (lastChosenFile != null) {
chooser.setSelectedFile(lastChosenFile);
} else {
File files[] = model.getBaseFolder().listFiles();
if (files != null && files.length > 0) {
chooser.setSelectedFile(files[0]);
} else {
chooser.setSelectedFile(model.getBaseFolder());
}
}
chooser.setDialogTitle(NbBundle.getMessage(OutputPanel.class, "LBL_Browse_Output")); // NOI18N
if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
for (File file : chooser.getSelectedFiles()) {
file = FileUtil.normalizeFile(file);
listModel.addElement(file.getAbsolutePath());
lastChosenFile = file;
}
applyChanges();
updateButtons();
}
}
示例4: actionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e)
{
JFileChooser fc = new JFileChooser(lastSelectedDirectory);
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
fc.setMultiSelectionEnabled(true);
if( fc.showOpenDialog(fileList) == JFileChooser.APPROVE_OPTION )
{
File[] selectedFiles = fc.getSelectedFiles();
if( selectedFiles != null && selectedFiles.length > 0 )
{
lastSelectedDirectory = selectedFiles[0];
if( !lastSelectedDirectory.isDirectory() )
{
lastSelectedDirectory = lastSelectedDirectory.getParentFile();
}
uploadFiles(fileList.getCurrentDirectory(), selectedFiles);
}
}
}
示例5: open
import javax.swing.JFileChooser; //导入方法依赖的package包/类
void open() throws IOException {
JFileChooser chooser = haxby.map.MapApp.getFileChooser();
int mode = chooser.getFileSelectionMode();
boolean multi = chooser.isMultiSelectionEnabled();
chooser.setMultiSelectionEnabled( true );
chooser.setFileSelectionMode( JFileChooser.FILES_ONLY );
chooser.addChoosableFileFilter(imageFileFilter);
int ok = chooser.showOpenDialog(frame);
File[] choice = null;
if( ok!=chooser.CANCEL_OPTION ) choice = chooser.getSelectedFiles();
chooser.setMultiSelectionEnabled(multi);
chooser.setFileSelectionMode( mode );
chooser.removeChoosableFileFilter(imageFileFilter);
if( ok==chooser.CANCEL_OPTION ) {
return;
}
if (mapType == MapApp.MERCATOR_MAP)
openImagesMercator(choice);
else
openImagesPolar(choice);
}
示例6: addFileButtonActionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void addFileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addFileButtonActionPerformed
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setMultiSelectionEnabled(true);
chooser.setDialogTitle(NbBundle.getMessage(SpringCustomizerPanel.class, "LBL_ChooseFile")); //NOI18N
chooser.setCurrentDirectory(basedir);
int option = chooser.showOpenDialog(SwingUtilities.getWindowAncestor(groupFilesList));
if (option == JFileChooser.APPROVE_OPTION) {
boolean showDialog = false;
List<File> newFiles = new LinkedList<File>();
StringBuilder existing = new StringBuilder(
NbBundle.getMessage(SpringCustomizerPanel.class, "LBL_FileAlreadyAdded")).append("\n"); //NOI18N
for (File file : chooser.getSelectedFiles()) {
if (files.contains(file)) {
existing.append(file.getAbsolutePath()).append("\n"); //NOI18N
showDialog = true;
} else {
newFiles.add(file);
}
}
// remember last location
basedir = chooser.getCurrentDirectory();
addFiles(newFiles);
if (showDialog) {
DialogDisplayer.getDefault().notify(
new NotifyDescriptor.Message(existing.toString(), NotifyDescriptor.ERROR_MESSAGE));
}
}
}
示例7: showMultiOpenDialog
import javax.swing.JFileChooser; //导入方法依赖的package包/类
/**
* Show an open dialog that allows multiple selection.
* @return An array of files, or null if the user cancelled the dialog
*/
public File[] showMultiOpenDialog() {
JFileChooser chooser = createFileChooser();
chooser.setMultiSelectionEnabled(true);
int result = chooser.showOpenDialog(findDialogParent());
if (JFileChooser.APPROVE_OPTION == result) {
File[] files = chooser.getSelectedFiles();
return files == null ? new File[0] : files;
} else {
return null;
}
}
示例8: chooseFilesToOpen
import javax.swing.JFileChooser; //导入方法依赖的package包/类
/**
* Displays the specified file chooser and returns a list of selected files.
*
* @param chooser file chooser to display
* @return array of selected files,
* @exception org.openide.util.UserCancelException
* if the user cancelled the operation
*/
public static File[] chooseFilesToOpen(JFileChooser chooser)
throws UserCancelException {
File[] files;
do {
int selectedOption = chooser.showOpenDialog(
WindowManager.getDefault().getMainWindow());
if (selectedOption != JFileChooser.APPROVE_OPTION) {
throw new UserCancelException();
}
files = chooser.getSelectedFiles();
} while (files.length == 0);
return files;
}
示例9: recordApproveSelection
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void recordApproveSelection(JFileChooser fc) {
if (fc.isMultiSelectionEnabled()) {
File[] fs = fc.getSelectedFiles();
recorder.recordSelect(this, ChooserHelper.encode(fs));
} else {
File file = fc.getSelectedFile();
recorder.recordSelect(this, ChooserHelper.encode(file));
}
}
示例10: chooseMossFileBtnActionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
/**
* choose the files for moss
*/
private void chooseMossFileBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseMossFileBtnActionPerformed
// TODO add your handling code here:
JFileChooser chooseMoss = new JFileChooser();
chooseMoss.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooseMoss.setMultiSelectionEnabled(true);
chooseMoss.showOpenDialog(this);
allMossFiles = chooseMoss.getSelectedFiles();
for(File f : allMossFiles) {
addedFilesArea.append(f.getAbsolutePath()+"\n");
}
}
示例11: selectFile
import javax.swing.JFileChooser; //导入方法依赖的package包/类
/**
* browse and select the attachment files
*/
private void selectFile() {
JFileChooser chooser = new JFileChooser(com.cognizant.cognizantits.ide.main.explorer.settings.Settings.getScreenShotLoc());
chooser.setMultiSelectionEnabled(true);
chooser.showOpenDialog(this);
File[] files = chooser.getSelectedFiles();
for (File f : files) {
attachments.setText(attachments.getText() + f.getAbsolutePath() + File.pathSeparator);
}
}
示例12: filterUI
import javax.swing.JFileChooser; //导入方法依赖的package包/类
@Override
public File[] filterUI() {
JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter(
"XML Files", "xml");
chooser.setFileFilter(filter);
chooser.setMultiSelectionEnabled(true);
int returnVal = chooser.showOpenDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION) {
return chooser.getSelectedFiles();
} else {
return null;
}
}
示例13: filterUI
import javax.swing.JFileChooser; //导入方法依赖的package包/类
@Override
public File[] filterUI() {
JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter(
"JSON Files", "json");
chooser.setFileFilter(filter);
chooser.setMultiSelectionEnabled(true);
int returnVal = chooser.showOpenDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION) {
return chooser.getSelectedFiles();
} else {
return null;
}
}
示例14: selectFiles
import javax.swing.JFileChooser; //导入方法依赖的package包/类
public static String[] selectFiles(Component component,String name,String extension,File pathToUse){
JFileChooser chooser = new JFileChooser();
chooser.setMultiSelectionEnabled(true);
if(extension != null){
chooser.setFileFilter(new ExtensionFilter(extension));
}
boolean useIndicated = pathToUse != null;
if (useIndicated && lastIndicatedPath == null){
lastIndicatedPath = pathToUse;
}
chooser.setCurrentDirectory(useIndicated?lastIndicatedPath:lastChooserPath);
int result = chooser.showDialog(component, name);
if ( result == JFileChooser.APPROVE_OPTION){
try{
if(useIndicated){
lastIndicatedPath = chooser.getCurrentDirectory();
}else{
lastChooserPath = chooser.getCurrentDirectory();
}
File[] files = chooser.getSelectedFiles();
String[] forReturn = new String[files.length];
for(int i = 0; i < files.length; i++){
forReturn[i] = files[i].getAbsolutePath();
}
return forReturn;
}catch(Exception e){e.printStackTrace();}
}
return null;
}
示例15: open
import javax.swing.JFileChooser; //导入方法依赖的package包/类
public File[] open(final JPanel panel) {
JFileChooser fc = new JFileChooser();
fc.setMultiSelectionEnabled(true);
fc.setCurrentDirectory(new File(System.getProperty("user.dir")));
fc.setDialogTitle("Choose File(s)");
fc.showOpenDialog(panel);
return fc.getSelectedFiles();
}