Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4140059

JFileChooser shows content of multiple directories

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P1 P1
    • 1.2.0
    • 1.0.2, 1.1.5, 1.1.6, 1.2.0
    • client-libs
    • None
    • 1.2fcs
    • generic, x86
    • generic, windows_95, windows_nt
    • Not verified

      I have discovered one not simply repeatable but very annoying problem in
      JFileChooser. My environment is Swing 1.02, JRE 1.1.6, Windows NT 4.0,
      Pentium 200 MMX, 64 Mb of RAM. The problem mostly appears if JIT is
      turned on (that is with the following command line: "jre -classpath
      %CLASSPATH% FileChooserDups").

      The problem is: in attached test case, in directory pane the content of
      BOTH directories appears at the same time: my home directory (d:\ in
      this case) and the directory where I do setCurrentDirectory()
      (c:\pav\pro).

      The test case follows (you will have to change hard-coded directory name
      "c:\\pav\\pro" to some place existing on your system other than your home directory):

      //----cut here-----
      /**
       * Q. it seems that JFileChooser sometimes duplicates a list of files
       * to be shown if run with jit (Swing. 1.0.2, JDK1.1.6)
       * A. Yes, it is mostly reproducable (70%).
       */
      import com.sun.java.swing.JButton;
      import com.sun.java.swing.JFrame;
      import com.sun.java.swing.UIManager;
      import com.sun.java.swing.preview.JFileChooser;
      import com.sun.java.swing.preview.filechooser.FileFilter;

      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import java.awt.event.WindowEvent;
      import java.awt.event.WindowAdapter;
      import java.io.File;

      public class FileChooserDups
        {
        public static void main(String [] args)
          {
          try
            {
           
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            }
          catch(Exception e)
            {
            System.err.println("Cannot set system defauls L&F:" + e );
            System.exit(0);
            }
          final JFrame tf = new JFrame("Test JFrame");
          JButton showFCButton = new JButton("Choose File...");
          showFCButton.addActionListener(new ActionListener()
            {
            public void actionPerformed(ActionEvent e)
              {
              File dir = new File(System.getProperty("user.home"));
              JFileChooser fc = new JFileChooser(dir);
              fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
              fc.setDialogTitle("Select directory for new project");
              fc.setFileFilter(new FileFilter()
                {
                public boolean accept(File f)
                  { return f.isDirectory(); }
                public String getDescription()
                  { return "Directories"; }
                });
              fc.setCurrentDirectory(new File("c:\\pav\\pro"));
              if(fc.showOpenDialog(tf) ==
                  JFileChooser.APPROVE_OPTION)
                System.out.println(fc.getSelectedFile().getPath());
              else
                System.out.println("Dialog cancelled");
              }
            });
          tf.setBounds(200, 100, 400, 200);
          tf.getContentPane().add(showFCButton);
          tf.addWindowListener(new WindowAdapter()
            {
            public void windowClosing(WindowEvent e) { System.exit(0); }
            });
          tf.show();
          }
        }
      //----cut here-----

            jeff Jeff Dinkins
            rkarsunw Ralph Kar (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: