1 Reply Latest reply: Oct 8, 2004 9:45 PM by 807587 RSS

    Something weird when Manually put the file path in JFileChooser

    807587
      Here are the steps I got the result
      1. copy one file to another directory (copy d:\log\aaa.txt d:\aaa.txt)
      2. open the JFileChooser dialog box
      3. change to one of the directory in 1. (here I say d:\)
      4. click on aaa.txt, and click on it again after 2 sec., and then the name is editable.
      5. Ctrl - c to copy the file name ("aaa.txt")
      6. key in the path "d:\log\" into the "File Name:" box
      7. Ctrl - v to paste the file name "aaa.txt" in to "File Name:" box, so the path name is "d:\log\aaa.txt" now
      8. click OK
      9. nothing happens...... cannot get the file from JFileChooser after that.

      has anyone experienced this problem?
      Thanks

      Jeffrey
        • 1. Re: Something weird when Manually put the file path in JFileChooser
          807587
          Here is the code. Thanks!!
          import javax.swing.*;
          import java.io.*;
          
          class test extends JFrame
          {
            public test(JFrame root)
            {
              JFileChooser jfc = new JFileChooser();
              jfc.setMultiSelectionEnabled(true);
              jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
              if (jfc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
                File[] files = jfc.getSelectedFiles();
          
                if (files != null) {
                  System.out.println(files[0]);
                }
              } else {
                System.out.println("Cancelled.");
              }
            }
          
            public static void main(String[] args)
            {
              JFrame frame = new JFrame("test");
              new test(frame);
              frame.dispose();
              System.exit(0);
            }
          }