如何使用swing创建文件夹中所有文件的列表? [英] How to make List with all files in folder using swing?

查看:72
本文介绍了如何使用swing创建文件夹中所有文件的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一个文件夹中的文件名列出一个列表,并显示该文件夹中所有具有特定扩展名的文件.我希望列表是可选择的,以便我可以从列表中选择和删除文件或对其进行编辑.我知道如何从文件夹中选择所有文件,但不知道如何在

I want to make a list with filename from a folder and show all the files that are present in that folder with a particular extension. I want the list to be selectable so that I can select and delete the file from the list or edit it. I know how to select all files from a folder but don't know how to show it in GUI.

File folder = new File("c:/");
File[] listOfFiles = folder.listFiles();

推荐答案

示例显示了如何枚举以下文件:目录并显示在 JToolBar JMenu .您可以使用Action(例如RecentFile)来封装行为,以供您在 ListModel ListSelectionListener .

This example shows how to enumerate the files in a directory and display them in a JToolBar and a JMenu. You can use an Action, such as RecentFile, to encapsulate behavior for use in your ListModel and ListSelectionListener.

这篇关于如何使用swing创建文件夹中所有文件的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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