0
我想爲我的JFileChooser設置文件過濾器。這是我的代碼:JFileChooser幫助
JFileChooser picker= new JFileChooser();
picker.setFileFilter(new FileNameExtensionFilter("txt"));
int pickerResult = picker.showOpenDialog(getParent());
if (pickerResult == JFileChooser.APPROVE_OPTION){
System.out.println("This works!");
}
if (pickerResult == JFileChooser.CANCEL_OPTION){
System.exit(1);
}
當我運行我的程序時,文件選擇器出現,但它不會讓我選擇任何.txt文件。相反,它在控制檯中表示:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Extensions must be non-null and not empty
我該如何解決這個問題?
可能重複http://stackoverflow.com/問題/ 5279358/JFileChooser的幫助) – 2014-04-15 14:36:12