We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › How to create FilenameFilter
Page Index Toggle Pages: 1
How to create FilenameFilter (Read 1110 times)
How to create FilenameFilter
May 25th, 2010, 9:58am
 
Hi

Check out code below please:

Code:

FileDialog fd = new FileDialog(this.frame, "Export");
fd.setMode(FileDialog.SAVE);
fd.setLocation(50, 50);
fd.show();
String dir = fd.getDirectory();
String file = fd.getFile();

if( dir != null && file != null) {
String path = dir+file;
if (!file.toLowerCase().endsWith(".dat")) {
path += ".dat";
}
PrintWriter out;
out = createWriter(path);
out.println("data");
out.close();
}


and tell me how to create FilenameFilter for this filedialog ?
I would like to have only *.dat and *.* file extentions to chose.
Re: How to create FilenameFilter
Reply #1 - May 25th, 2010, 10:08am
 
Search the forum... This comes up regularly.
I think you cannot with FileDialog (AWT dialog), I gave workaround elsewhere.
Re: How to create FilenameFilter
Reply #2 - May 25th, 2010, 11:19am
 
I have found an example:

http://www.java-samples.com/showtutorial.php?tutorialid=384

Maybe it's possible to use the code below in my implementation

Code:

import java.io.*;
public class OnlyExt implements FilenameFilter {
String ext;
public OnlyExt(String ext) {
this.ext = "." + ext;
}
public boolean accept(File dir, String name) {
return name.endsWith(ext);
}
}

FilenameFilter only = new OnlyExt("dat");


how to use it? help
Re: How to create FilenameFilter
Reply #3 - May 25th, 2010, 4:02pm
 
I meant to search the forum itself...
I did the search myself, found back the thread: Browse.
Page Index Toggle Pages: 1