JDK-4906054 : Multiple modules cannot be selected in a JFileChooser on Solaris w Motif L&F
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.1
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_8
  • CPU: sparc
  • Submitted: 2003-08-13
  • Updated: 2003-09-22
  • Resolved: 2003-09-22
Related Reports
Duplicate :  
Description

Name: pa48320			Date: 08/13/2003


Steps to reproduce:
1. Compile and run DialogTest.java
2. Press "Open a File" button which brings up the JFileChooser.
3. Try selecting more than one module. It is not possible. Even if 2 modules are selected, what appears in the "Enter File Name" is only one module and so only one module is selected.
Please note that this bug is specific to solaris only. If the same steps are followed on an NT, the JFileChooser selects multiple modules.

Source code:
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) {
                    //System.out.println("Approved " + newline);
                    File[] selectedFiles = fc.getSelectedFiles();
                    for ( int i=0; i < selectedFiles.length; i++)
                        System.out.println(" Files Selected:" + selectedFiles[i]
.toString());
                }
                else {
                    System.out.println("Open command cancelled by user." + newli
ne);
                }
                //fc.setSelectedFile(new File(""));
            }
        });
        //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 {
        System.out.println("LookAndFeel Selected is " + UIManager.getSystemLookA
ndFeelClassName());
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
        catch(Exception e) { System.out.println("An exception is raised by UIMan
ager.setLookAndFeel\n"); }
        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";
        }
}

}
(Incident Review ID: 198979) 
======================================================================

Comments
WORK AROUND Name: pa48320 Date: 08/13/2003 None ======================================================================
11-06-2004