I had problems with the JFileChooser when I simply type a filename in
the textfield, without selecting something before. In that case the
filechooser won't close when I hit the 'save' button. This is fixed by
the attached patch.

2006-03-19  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/plaf/basic/BasicFileChooserUI.java
        (ApproveSelectionAction.actionPerformed): Added case for when
        nothing has been selected but the user has typed a filename
        into the textfield.
        (getFileName): Return the value of the text field.

/Roman
-- 
“Improvement makes straight roads, but the crooked roads, without
Improvement, are roads of Genius.” - William Blake
Index: javax/swing/plaf/basic/BasicFileChooserUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicFileChooserUI.java,v
retrieving revision 1.23
diff -u -r1.23 BasicFileChooserUI.java
--- javax/swing/plaf/basic/BasicFileChooserUI.java	4 Jan 2006 17:02:32 -0000	1.23
+++ javax/swing/plaf/basic/BasicFileChooserUI.java	19 Mar 2006 20:19:03 -0000
@@ -157,6 +157,21 @@
               closeDialog();
             }
         }
+      else
+        {
+          File f = new File(filechooser.getCurrentDirectory(), getFileName());
+          if (filechooser.isTraversable(f))
+            {
+              filechooser.setCurrentDirectory(f);
+              filechooser.rescanCurrentDirectory();
+            }
+          else
+            {
+              filechooser.setSelectedFile(f);
+              filechooser.approveSelection();
+              closeDialog();
+            }
+        }
     }
   }
 
@@ -1046,9 +1061,7 @@
    */
   public String getFileName()
   {
-    // FIXME: I'm thinking that this method just provides access to the
-    // text value in the JTextField component...but not sure yet
-    return null;  //filename;
+    return entry.getText();
   }
 
   /**

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil

Reply via email to