JDK-4125509 : A couple of problems in JFileChooser
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.0
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: solaris_2.6
  • CPU: generic
  • Submitted: 1998-04-03
  • Updated: 1998-05-29
  • Resolved: 1998-05-29
Related Reports
Relates :  
Description
There are a couple of problems in JFileChooser:
1) The directory field "Look in:" in JFileChooser never get updated during file navigation.
2) JFileChooser doesn't validate the file name which are entered in "File Name" field by user - This is unacceptable, there should be a message to warn user that the file doesn't exist.

The following test demonstates the problems:
 
import java.awt.swing.*;
import java.awt.swing.preview.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;

public class TestFileChooser extends JFrame
   implements ActionListener
{  public TestFileChooser()
   {  JMenuBar mbar = new JMenuBar();
      JMenu m = new JMenu("File");
      JMenuItem m1 = new JMenuItem("Open");
      m1.addActionListener(this);
      m.add(m1);            
      JMenuItem m2 = new JMenuItem("Exit");
      m2.addActionListener(this);
      m.add(m2);            
      mbar.add(m);

      JPanel p = new JPanel();
      p.setLayout(new BorderLayout());

      p.add("North", mbar);

      setContentPane(p);
   }

   public void actionPerformed(ActionEvent evt)
   {  String arg = evt.getActionCommand();
      if (arg.equals("Open"))
      {  JFileChooser d = new JFileChooser();
         d.showDialog(this);
      }
      else if(arg.equals("Exit")) System.exit(0);
   }   

   public static void main(String args[])
   {  JFrame frame = new TestFileChooser();
      frame.pack();
      // comment out the line below to see the menu bug
      frame.setSize(300, 400);
      frame.setVisible(true);
      frame.addWindowListener(new WindowAdapter() 
      {  public void windowClosing(WindowEvent e) 
         { System.exit(0); } 
      } );
   }
}






Comments
EVALUATION Bug 1 was a combobox bug - fixed. Bug 2 is not a bug - it's up to the developer to throw up a dialog saying that the file does not exist. (filechooser.getSelectedFile().exists().
11-06-2004