JDK-4062596 : File Filters In File Dialog Don't Work
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.1.1
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_95
  • CPU: x86
  • Submitted: 1997-07-01
  • Updated: 1998-01-29
  • Resolved: 1998-01-29
Related Reports
Duplicate :  
Description

Name: sg39081			Date: 07/01/97


/*

Compile and run this code. It allows you to see that filtering has not
effect on the file dialog under Win95 as documented.

   "Instances of classes that implement this interface are used to filter 
   filenames. These instances are used to filter directory listings in the 
   list method of class File, and by the Abstract Window Toolkit's file 
   dialog component."                   ==============================
   =================

Press the single button. See that although the the filter is supposed to
limit the files shown/selected to "*.java", it does not.

*/

import java.awt.*;
import java.awt.event.*;
import java.io.*;

public class jdk111FileDialogFilterBug extends Frame
                                       implements ActionListener,
                                                  FilenameFilter
{
   public jdk111FileDialogFilterBug()
   {
      Button b = new Button("File Dialog");
      add(b, "Center");
      b.addActionListener(this);
      doLayout();
      pack();
      show();
   }

   public void actionPerformed(ActionEvent e)
   {
      // show the user the file open dialog
      FileDialog dialog = new FileDialog(this, "Filter Test", FileDialog.LOAD);
      dialog.setFilenameFilter(this);
      dialog.show();

      // get the user's input
      String dir = dialog.getDirectory();
      String file = dialog.getFile();

      // get rid of the file dialog
      dialog.dispose();

      // if the user pressed the Cancel button on the dialog, then
      // the file will be null
      if(null == file)
      {
         System.out.println("Cancel");
         return;
      }

      // note the filename
      System.out.println(dir + file);
   }

   /**
   *** Filename filter to limit selections.
   **/
   public boolean accept(File dir, String name)
   {
      return(name.endsWith(".java"));
   }


   public static void main(String[] argv)
   {
      new jdk111FileDialogFilterBug();
   }
}



======================================================================

Comments
WORK AROUND Name: sg39081 Date: 07/01/97 ======================================================================
11-06-2004