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

A couple of problems in JFileChooser

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 1.2.0
    • client-libs
    • None
    • generic
    • solaris_2.6

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





            jeff Jeff Dinkins
            tsusunw Tina Su (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: