[英]Java JFileChooser filter files for “File.txt”
How can I make a JFileChooser Filter to filter for "File.txt", I can make it filter for just ".txt" but thats not what I want. 我如何制作一个JFileChooser过滤器以过滤“ File.txt”,我可以使其仅过滤“ .txt”,但这不是我想要的。
I'm going to have a String[] of files to filter for such as 我将要过滤一个String []文件,例如
String[] filters = new String[filtersCount];
String[0] = "File.txt";
String[1] = "Text.txt";
String[2] = "uncapText.txt";
I want to be able to browse for only files with those exact names, capitalization does also count so "uncapText.txt"
will be accepted but "UncapText.txt"
or "unCapText.txt"
won't. 我希望只能浏览具有这些确切名称的文件,大写字母也算在内,因此
"uncapText.txt"
将被接受,但"UncapText.txt"
或"unCapText.txt"
将不被接受。
This seems like an easy question but I couldn't find any topic on it. 这似乎是一个简单的问题,但我找不到任何主题。
I would suggest writing a filter that checks for... 我建议写一个过滤器来检查...
return Arrays.asList(filters).contains(file.getName());
In other words, make a List out of your array (to have a nice "contains" method) and then ask that list if the name of the file is contained in it. 换句话说,从您的数组中创建一个List(以使用漂亮的“ contains”方法),然后询问该列表是否包含文件名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.