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

Index exception in JFileChooser.setCurrentDirectory

XMLWordPrintable

      A DESCRIPTION OF THE PROBLEM :
      JFileChooser.setCurrentDirectory fails if setFileSelectionMode(DIRECTORIES_ONLY) is called first

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      final JFileChooser fc = new JFileChooser();
      final File file = new File("Some existing directory");
      fc.setDialogType(JFileChooser.SAVE_DIALOG);
      fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY)
      fc.setCurrentDirectory(file); // <= This line produces an index exceptions

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Change the current directory to the specified directory
      ACTUAL -
      An exception

      ---------- BEGIN SOURCE ----------
      final JFileChooser fc = new JFileChooser();
      final File file = new File("Some existing directory");
      fc.setDialogType(JFileChooser.SAVE_DIALOG);
      fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY)
      fc.setCurrentDirectory(file); // <= This line produces an index error
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      // Move setFileSelectionMode after setCurrentDirectory
      final JFileChooser fc = new JFileChooser();
      final File file = new File("Some existing directory");
      fc.setDialogType(JFileChooser.SAVE_DIALOG);
      fc.setCurrentDirectory(file);
      fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY)


      FREQUENCY : often


            tr Tejesh R
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: