JDK-4949273 : Inconsistent behaviour with JFileChooser on Winnt and Solaris
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.1_03
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2003-11-05
  • Updated: 2003-12-15
  • Resolved: 2003-12-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 b32Fixed
Related Reports
Relates :  
Description

Name: wm7046			Date: 11/05/2003


1. Compile and run the testcase
     javac -d . DialogTest.java
     java an.bn.DialogTest
2.  Press the button "Open the File" to bring up the JFileChooser
3. Select a file in the List of files and note that same thing is copied on to the "File Name" edit field.
4. Change the filename in the "File Name" edit field to a non-existing one say "XXX.fmb" and press Open button.
5. Note the return value getting printed on the Command prompt. This indicates that the FileChooser.getSelectedFiles().length is 0 though there is a file name entered in the "File Name" edit field.
6. Bring up the JFileChooser again and now without selecting any files in the List of Files, just enter some file name(non-existing)  in the "File Name" edit field.
7. Pressing the Open button, you will notice the output on the command prompt which indicates that the JFileChooser.getSelectedFiles().length has returned 1.

If you follow the same steps on Solaris, you will notice that for both the above mentioned cases, JFileChooser.getSelectedFiles().length is 1 and each time it returns the name of the file in the "File Name" edit field.

Testcase:
DialogTest.java
package an.bn;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.filechooser.*;
import java.util.StringTokenizer;

public class DialogTest extends JFrame {
    static private final String newline = "\n";
    JFileChooser fc = null;

    public DialogTest() {
        super("FileChooserDemo");

        //Create the log first, because the action listeners
        //need to refer to it.

        //Create a file chooser
        fc = new JFileChooser();
        fc.setMultiSelectionEnabled(true);
        TextFilter txt = new TextFilter();
        fc.setFileFilter(txt);
        fc.addChoosableFileFilter(txt);
        fc.setCurrentDirectory(new File(System.getProperty("user.dir")));


        //Create the open button
        JButton openButton = new JButton("Open a File...");
        openButton.setMnemonic(openButton.getText().charAt(0));
        openButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                int returnVal = fc.showOpenDialog(null);

                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    File[] selectedFiles = fc.getSelectedFiles();
                    System.out.println("number of files selected " + selectedFil
es.length);
                    for (int i=0;i<selectedFiles.length;i++)
                    {
                      System.out.println(selectedFiles[i].toString()+"\n");
                    }

                }
                else {
                    System.out.println("Open command cancelled by user." + newli
ne);
                }
            }
        });

        //For layout purposes, put the buttons in a separate panel
        JPanel buttonPanel = new JPanel(new FlowLayout());
        buttonPanel.add(openButton);

        //Add the buttons and the log to the frame
        Container contentPane = getContentPane();
        contentPane.add(buttonPanel);
    }

    public static void main(String[] args) {
        StringBuffer tm=new StringBuffer("\"");
        tm.append("THis is new");
        tm.append("\"");
                System.out.println(tm);
        try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
         }catch (Exception e) { System.out.println("UIManager.setLookAndFeel rai
sed Exception");}
        JFrame frame = new DialogTest();

        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }

        });

        frame.pack();
        frame.setVisible(true);
    }

class TextFilter extends javax.swing.filechooser.FileFilter
{
        public boolean accept(File f)
        {
                if ( f.isDirectory() || f.getName().endsWith("txt") || f.getName
().endsWith("TXT") )
                        return true;
                else
                        return false;
        }

        public String getDescription()
        {
                return "Text Files";
        }
}

}
(Review ID: 223309) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger-beta FIXED IN: tiger-beta INTEGRATED IN: tiger-b32 tiger-beta
14-06-2004

WORK AROUND Name: wm7046 Date: 11/05/2003 NA ======================================================================
11-06-2004

EVALUATION Reproducible with FileChooserDemo. ###@###.### 2003-11-18 If there is a selection in the list and the user types in a new name, then this causes the list to cleared in FilePane.setFileselected(), which in turn causes a new call to clear the selectedFiles property. This logic need to be looked over. The bug exists all the way back to 1.4. ###@###.### 2003-11-20
20-11-2003