![](/img/trans.png)
[英]How to browse the files only with extensions .xls using JFileChooser in swing
[英]How to how all files with either of two file extensions in JFileChooser OpenDialog
用戶將在JFileChooser中選擇一個文件,該文件將轉換為新的文件格式,然后以其他擴展名保存。 我想顯示帶有兩個擴展名的文件,以便用戶可以查看文件是否已經轉換。
我已經能夠添加兩個FileNameExtensionFilter方法,但這意味着用戶必須在它們之間切換。 是否有辦法過濾掉除兩個擴展之外的所有擴展? 替代方法似乎是不使用過濾器並接受所有文件。 (在遙遠的過去,我能夠在Windows中使用C / C ++做到這一點)
我在Ubuntu下使用Java。
只需使FileFilter
接受任一文件類型
public boolean accept(File f) {
if( /* File is first type */ || /* File is second type */)
return true;
return false;
}
編寫自定義過濾器:
fc.setFileFilter(new FileFilter() {
public boolean accept(File f) {
if( checkForFileTypeOne() || checkForFileTypeTwo()) {
return true;
}
return false;
}
public String getDescription() {
return "Usefull files (*.abc, *.def)";
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.