使用JFileChooser添加多个文件 [英] Adding multiple files with JFileChooser

查看:58
本文介绍了使用JFileChooser添加多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个允许您从计算机附加文件的应用程序.例如,当JFileChooser打开时,您可以选择多个文件,而当您单击添加"时,它将添加到窗口中,然后您可以对这些文件进行不同的选择.类似于在电子邮件中附加文件.我要显示的所有代码都是JFileChooser,因为我认为在继续之前,我应该学习如何做.

I'm looking to make an application that allows you to attach files from your computer. For example, when the JFileChooser opens you have the option to select multiple files and when you click "add" it adds it to the window and you can then have different for what you want to do with those files. Similar to attaching files in an email. All the code I have to show is the JFileChooser because I figure I should learn how to do this before I go any further.

预先感谢

import javax.swing.JFileChooser;
import java.io.File;

public class Locket {

public static void main(String[] args) 
{
    JFileChooser chooser = new JFileChooser();
    File f = new File("Desktop");
    chooser.setCurrentDirectory(f);

    chooser.showOpenDialog(null);

}

}

推荐答案

JFileChooser API已经提供了名为getSelectedFiles()的方法.您可以将其用于多项选择.它返回文件对象数组,即File[].

JFileChooser API already provides a method named getSelectedFiles(). You can use it for multiple selection. It returns an array of file objects, i.e. File[].

这篇关于使用JFileChooser添加多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆