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

FileChooser textbox for filename does not release name after reading.

XMLWordPrintable

      FULL PRODUCT VERSION :
      Product Version: NetBeans IDE 6.9 (Build 201006101454)
      Java: 1.6.0_10; Java HotSpot(TM) Client VM 11.0-b15
      System: Windows XP version 5.1 running on x86; Cp1252; en_US (nb)
      Userdir: C:\Documents and Settings\danny.rich\.netbeans\6.9

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows ver 2002 service pack 2

      A DESCRIPTION OF THE PROBLEM :
      First application of JFileChooser shows the File & Directory window with the filename box empty. Second application retains the last used file name & extension, even if the previous extension is not consistent with the currently active extension filter.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create JFileChooser dialog
      Set File extension filter
      Show OpenDialog
      Change File extension filter
      Show SaveDialog
      {Opened file name & extension are shown in the Save file name textbox}

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Either the SaveDialog file name textbox should be set to NULL as at first or the extension of the retained filename should be changed to the FileExtensionFilter value.
      ACTUAL -
      A SaveDialog with filter for .CXF extension showed a filename with MIF extension. This is a potential error for the user that will overwrite the first file with modified data.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      private void openMIFActionPerformed(java.awt.event.ActionEvent evt) {
              // TODO add your handling code here:
              FileNameExtensionFilter filter = new FileNameExtensionFilter("MIF Files","mif");
              fileChooser.addChoosableFileFilter(filter);
              int retValue = fileChooser.showOpenDialog(this.getFrame());
              if (retValue == fileChooser.APPROVE_OPTION) {
      // Open the MIF file checking for IOExceptions
                  try {
                      File mifFile = fileChooser.getSelectedFile();
                      Scanner scan = new Scanner(mifFile);

      <snip>

      private void convertMIFActionPerformed(java.awt.event.ActionEvent evt) {
              // TODO add your handling code here:
      // Create the CXF file to accept the color standard data from the MIF file
              FileNameExtensionFilter filter = new FileNameExtensionFilter("CXF Files","cxf");
              fileChooser.addChoosableFileFilter(filter);
              int retValue = fileChooser.showSaveDialog(this.getFrame());
              if (retValue == fileChooser.APPROVE_OPTION) {
                  PrintWriter cxfOut = null;
                  NumberFormat nfmt = new DecimalFormat("####.#####");
      // CXF is a form of XML without DTD or data definition or validation rules
      // Create and open the file looking for IOExceptions
      // Much of the content of a CXF file is fixed data.
      // This conversion uses CXF v1.0 which has the simplest format
                  try {
                      File cxfFile = fileChooser.getSelectedFile();
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      User must manually enter the new filename and extension or at the very least delete the old extension and enter the new extension.

            rupashka Pavel Porvatov (Inactive)
            igor Igor Nekrestyanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: