🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #20070

Re: How can I set the file filters in the filedialog?

#20070
From: Real Gagnon
Date: Tue, 28 Oct 1997 00:00
69 lines
2851 bytes
jozsef bodnar a �crit:

> 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");
>  }
>

On the Win platform, the setFilenameFilter/accept method don't work. We must
use
the setFile method instead to set a filter.

A snippet from my JAVA How-to at
http://www.geocities.com/SiliconValley/Vista/1337

import java.awt.*;
public class UseFileDialog {

  public String loadFile(Frame f, String title, String defDir, String
fileType) {
    FileDialog fd = new FileDialog(f, title, FileDialog.LOAD);
    fd.setFile(fileType);
    fd.setDirectory(defDir);
    fd.setLocation(50, 50);
    fd.show();
    return fd.getFile();
    }

  public String saveFile(Frame f, String title, String defDir, String
fileType) {
    FileDialog fd = new FileDialog(f, title,    FileDialog.SAVE);
    fd.setFile(fileType);
    fd.setDirectory(defDir);
    fd.setLocation(50, 50);
    fd.show();
    return fd.getFile();
    }

  public static void main(String s[]) {
    UseFileDialog ufd = new UseFileDialog();
    System.out.println
      ("Loading : " + ufd.loadFile(new Frame(), "Open...", ".\\",
"*.java"));
    System.out.println
      ("Saving : " + ufd.saveFile(new Frame(), "Save...", ".\\", "*.java"));

    System.exit(0);
    }
}

--
//          Real Gagnon     mailto:gagnonr@gespro.com
// [Real's Home **JAVA & JAVAScript How-to** for useful snippets ]
//         http://www.geocities.com/SiliconValley/Vista/1337
Technical Details
Message-ID: <3455F641.13E9EE65@gespro.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <345214FD.4907DA6E@globalinfotek.com> <62ug25$3e36@forums.borland.com> <3455C560.8D305F9F@gold.uni-miskolc.hu>

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: Real Gagnon <gagnonr@gespro.com>
Subject: Re: How can I set the file filters in the filedialog?
Date: 1997/10/28
Message-ID: <3455F641.13E9EE65@gespro.com>
X-Deja-AN: 285556558
References: <345214FD.4907DA6E@globalinfotek.com> <62ug25$3e36@forums.borland.com> <3455C560.8D305F9F@gold.uni-miskolc.hu>
To: jozsef bodnar <szkbodna@gold.uni-miskolc.hu>
Organization: Gespro Informatique inc.
Reply-To: gagnonr@gespro.com
Newsgroups: borland.public.jbuilder.java.language,comp.lang.java.programmer