Dillinger4
May 1st, 2005, 08:16 PM
Anyone know what i might be doing wrong. I can see that when jfc.showOpenDialog(jf); is called all of the files within the current directory are being scanned cause i can see them flying through the dos window, but when i change the extension in the FileDialog the files that come up within the JFileChooser aren't being filtered.
openfile.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
class JavaFilter extends javax.swing.filechooser.FileFilter{
public boolean accept(File file){
String filename = file.getName();
String extension = filename.substring(0, filename.length());
System.out.println(extension);
if(extension.equals(".java")){
return true;
}
return false;
}
public String getDescription() {
return ".java Files";
}
}
JFileChooser jfc = new JFileChooser();
jfc.setFileFilter(new JavaFilter());
jfc.showOpenDialog(jf);
}
});
openfile.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
class JavaFilter extends javax.swing.filechooser.FileFilter{
public boolean accept(File file){
String filename = file.getName();
String extension = filename.substring(0, filename.length());
System.out.println(extension);
if(extension.equals(".java")){
return true;
}
return false;
}
public String getDescription() {
return ".java Files";
}
}
JFileChooser jfc = new JFileChooser();
jfc.setFileFilter(new JavaFilter());
jfc.showOpenDialog(jf);
}
});