日期:2014-05-20 浏览次数:20845 次
public String GetFileChooser(String strExt,String strButton,boolean bSave) { final String str = strExt;//加上这句.. 内部类要引用外部类的变量..该变量必须是final的. JFileChooser jf = new JFileChooser("."); jf.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); jf.setFileFilter(new javax.swing.filechooser.FileFilter() { public boolean accept(File f) { String filePath = f.getAbsoluteFile().toString().toUpperCase(); if (filePath.endsWith(str)) return true; else return false; } public String getDescription() { return str; } }); jf.setApproveButtonText(strButton); int result = -1; if (bSave) result = jf.showSaveDialog(null); else result = jf.showOpenDialog(null); if (result == JFileChooser.APPROVE_OPTION) return jf.getSelectedFile().getPath(); else return null; } }