PDA

Click to See Complete Forum and Search --> : JFileChooser Hide file type


xxarmoxx
Jul 12th, 2007, 03:25 PM
How can I hide certain files in a JFileChooser control? This is what Im using so far but I can still see files I dont want to see.

JFrame frame = new JFrame();


String filename = "Desktop";
JFileChooser fc = new JFileChooser(new File(filename));



fc.setFileFilter(new FileFilter() {
public String getDescription() { return "CSV files"; }
public boolean accept(File f) {
if(f.isDirectory()) return true;
if(f.getName().endsWith(".csv")) return true;
return false;
}
});



// Show save dialog; this method does not return until the dialog is closed
fc.showSaveDialog(frame);
cFile = fc.getSelectedFile();

System_Error
Jul 12th, 2007, 07:57 PM
Can you explain a little more? I don't know what files you don't want to see and what it's showing up.

ComputerJy
Jul 13th, 2007, 06:12 AM
I tried this code: public void actionPerformed(ActionEvent e)
{
JFileChooser chooser=new JFileChooser();
chooser.addChoosableFileFilter(new FileFilter(){

public boolean accept(File f)
{
if(f.isDirectory())return true;
else if(f.getName().endsWith(".csv"))return true;
else return false;
}

public String getDescription()
{
return "Comma separated file";
}
});
if(chooser.showOpenDialog(null)==JFileChooser.APPROVE_OPTION)
{
//Do your things
}
} and it works