|
-
Jul 12th, 2007, 03:25 PM
#1
Thread Starter
Hyperactive Member
JFileChooser Hide file type
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.
Code:
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();
-
Jul 12th, 2007, 07:57 PM
#2
Frenzied Member
Re: JFileChooser Hide file type
Can you explain a little more? I don't know what files you don't want to see and what it's showing up.
-
Jul 13th, 2007, 06:12 AM
#3
Re: JFileChooser Hide file type
I tried this code:
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
Last edited by ComputerJy; Jul 13th, 2007 at 06:19 AM.
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|