changeset 4091:6c94f33c36d5

7021058: The Create folder button produces error in the Details mode (JFileChooser) Reviewed-by: malenkov
author rupashka
date Thu, 21 Apr 2011 14:29:23 +0400
parents ea0aed4b75cd
children 91a590306e02
files src/share/classes/sun/swing/FilePane.java
diffstat 1 files changed, 14 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/swing/FilePane.java	Wed Apr 20 16:46:31 2011 +0400
+++ b/src/share/classes/sun/swing/FilePane.java	Thu Apr 21 14:29:23 2011 +0400
@@ -763,7 +763,7 @@
 
         public void setValueAt(Object value, int row, int col) {
             if (col == COLUMN_FILENAME) {
-                JFileChooser chooser = getFileChooser();
+                final JFileChooser chooser = getFileChooser();
                 File f = (File)getValueAt(row, col);
                 if (f != null) {
                     String oldDisplayName = chooser.getName(f);
@@ -782,18 +782,25 @@
 
                         // rename
                         FileSystemView fsv = chooser.getFileSystemView();
-                        File f2 = fsv.createFileObject(f.getParentFile(), newFileName);
+                        final File f2 = fsv.createFileObject(f.getParentFile(), newFileName);
                         if (f2.exists()) {
                             JOptionPane.showMessageDialog(chooser, MessageFormat.format(renameErrorFileExistsText,
                                     oldFileName), renameErrorTitleText, JOptionPane.ERROR_MESSAGE);
                         } else {
                             if (FilePane.this.getModel().renameFile(f, f2)) {
                                 if (fsv.isParent(chooser.getCurrentDirectory(), f2)) {
-                                    if (chooser.isMultiSelectionEnabled()) {
-                                        chooser.setSelectedFiles(new File[]{f2});
-                                    } else {
-                                        chooser.setSelectedFile(f2);
-                                    }
+                                    // The setSelectedFile method produces a new setValueAt invocation while the JTable
+                                    // is editing. Postpone file selection to be sure that edit mode of the JTable
+                                    // is completed
+                                    SwingUtilities.invokeLater(new Runnable() {
+                                        public void run() {
+                                            if (chooser.isMultiSelectionEnabled()) {
+                                                chooser.setSelectedFiles(new File[]{f2});
+                                            } else {
+                                                chooser.setSelectedFile(f2);
+                                            }
+                                        }
+                                    });
                                 } else {
                                     // Could be because of delay in updating Desktop folder
                                     // chooser.setSelectedFile(null);