Article View: borland.public.jbuilder.java.language
Article #20067Re: How can I set the file filters in the filedialog?
From: jozsef bodnar
Date: Tue, 28 Oct 1997 00:00
Date: Tue, 28 Oct 1997 00:00
64 lines
2037 bytes
2037 bytes
Hi,
I had been trying the following code snippet before I read your answer
but the title and the filename filter don�t work.
I can�t recognise what is the difference between your and my code except
for my filename filter is implemented in �this� object.
Could you explain why doesn�t work my application ?
I use jdk 1.1.1 on Win NT 4.0
class Monument extends Frame
implements
ActionListener,KeyListener,FilenameFilter,AdjustmentListener {
.
.
FileDialog PictureFiles = new FileDialog(this,"Select a picture
file",FileDialog.LOAD);
PictureFiles.setFilenameFilter(this);
PictureFiles.setVisible(true);
.
.
.
public boolean accept(File dir , String filename) {
return filename.endsWith(".jpg");
}
Thanks in advance,
jozsef bodnar
Chris Hill wrote:
>
> In article <345214FD.4907DA6E@globalinfotek.com>,
> jschnur@globalinfotek.com says...
> >
> >How can We set the file filter types like *.csv , *.txt, etc for the
> >openfiledialog.?
> >
>
> Write a class that implements java.io.FilenameFilter.
>
> For example:
>
> public class MyFilter implements java.io.FilenameFilter
> {
> public boolean accept(File dir, String name)
> {
> if(name.endsWith(".csv") || name.endsWith(".txt"))
> return true;
> else
> return false;
> }
> }
>
> Now call MyFileDialog.setFilenameFilter(new MyFilter()).
>
> --
> Chris Hill
> hillca@cs.purdue.edu
Technical Details
Message-ID:
<3455C560.8D305F9F@gold.uni-miskolc.hu>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<345214FD.4907DA6E@globalinfotek.com> <62ug25$3e36@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 10a146,92945f7790f60b99 X-Google-Attributes: gid10a146,public X-Google-Thread: f74b3,92945f7790f60b99 X-Google-Attributes: gidf74b3,public From: jozsef bodnar <szkbodna@gold.uni-miskolc.hu> Subject: Re: How can I set the file filters in the filedialog? Date: 1997/10/28 Message-ID: <3455C560.8D305F9F@gold.uni-miskolc.hu> X-Deja-AN: 285502839 References: <345214FD.4907DA6E@globalinfotek.com> <62ug25$3e36@forums.borland.com> Organization: IIF Newsgroups: borland.public.jbuilder.java.language,comp.lang.java.programmer