来自 unix 机器的 Java Swing ComboBox 文件列表 [英] Java Swing ComboBox list of files from unix machine
问题描述
我正在 UNIX 环境中运行我的第一个简单的 Java Swing 应用程序.目前,它有一个图像和一些可以随机执行操作的按钮 - 其中一个执行到我的 UNIX shell 的命令.
I'm running my first simple Java Swing application from my UNIX environment. Currently it has an image and some buttons that do random things - one of which executes a command to my UNIX shell.
我在 UNIX 机器上的一个目录中有一个.ksh"文件列表,我想将这些文件读入 Swing GUI ComboBox.
I have a list of ".ksh" files in one of my directories on the UNIX machine that I'd like to read into a Swing GUI ComboBox.
下拉项将从 UNIX 机器上目录中的文件列表中填充,当我单击列表中的文件时,它将在 UNIX shell 中执行脚本.我不太确定如何开始.
The dropdown items will populate from the list of files in the directory on the UNIX machine, and when i click a file from the list, it will execute the script in the UNIX shell. The I'm not quite sure how to start.
推荐答案
这样你就可以获得扩展名为.ksh"的文件列表(作为字符串数组):
This way you could get the list of the files (as string array) with the extension ".ksh":
File dir = new File(pathToDir);
String[] files;
FilenameFilter filter = new FilenameFilter() {
public boolean accept(File dir, String name) {
return !name.endWith(".ksh");
}
};
files = dir.list(filter);
然后迭代数组并向其添加名称.
Then iterate the array and add the names to it.
To execute a command on shell, see one of these many answers
这篇关于来自 unix 机器的 Java Swing ComboBox 文件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!