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

JFileChooser hangs on Windows XP when CrossPlatformLookAndFeel is used

    Details

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0_14"
      Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
      Java HotSpot(TM) Client VM (build 14.0-b16, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      Below are the conditions required to reproduce the problem:
      1. The operating system is Window XP.
      2. There is an instance of JFileChooser used many times to show the file dialog.
      3. The look-and-feel is CrossPlatformLookAndFeel.
      4. At lease one custom FileFilter is used by the JFileChooser instance.
      5. The FileFilter does not accept all files.
      6. The default directory opened by the JFileChooser instance contains at least one file accepted by the FileFilter.
      7. resetChoosableFileFilters() is called after showOpenDialog().
      If the conditions are all satisfied and the function showOpenDialog() (or showSaveDialog) of the JFileChooser instance is called many times, then it hangs eventually. The number of calls to showOpenDialog() required to make the JFileChooser hang is usually less than 20.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Run the attached program.
      2. Click on the Open button and cancel the opened file dialog.
      3. Repeat step 2 until the program hangs. (Usually less than 20 clicks are required.)

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The program should not hang when opening the file chooser dialog.
      ACTUAL -
      The program hangs eventually.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import java.io.File;

      import javax.swing.JButton;
      import javax.swing.JDialog;
      import javax.swing.JFileChooser;
      import javax.swing.JFrame;
      import javax.swing.UIManager;
      import javax.swing.UnsupportedLookAndFeelException;
      import javax.swing.filechooser.FileFilter;

      public class Main {

      public static void main(String[] args) {
      try {
      UIManager.setLookAndFeel(UIManager
      .getCrossPlatformLookAndFeelClassName());
      JFrame.setDefaultLookAndFeelDecorated(true);
      JDialog.setDefaultLookAndFeelDecorated(true);
      } catch (InstantiationException e) {
      e.printStackTrace();
      } catch (ClassNotFoundException e) {
      e.printStackTrace();
      } catch (UnsupportedLookAndFeelException e) {
      e.printStackTrace();
      } catch (IllegalAccessException e) {
      e.printStackTrace();
      }

      final JFileChooser chooser = new JFileChooser();
      final FileFilter filter = new FileFilter() {
      @Override
      public boolean accept(File f) {
      return f.getName().toLowerCase().endsWith(".txt");
      }

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

      final JFrame frame = new JFrame();

      JButton open = new JButton("Open");
      open.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
      chooser.addChoosableFileFilter(filter);
      chooser.setFileFilter(filter);
      chooser.showOpenDialog(frame);
      chooser.resetChoosableFileFilters();
      }
      });
      frame.getContentPane().add(open);

      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setSize(200, 100);
      frame.setVisible(true);
      }

      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      If one of the conditions is not satisfied, the problem does not occur. For example:
      1. use Linux,
      2. create an instance of JFileChooser whenever we want to show the file dialog,
      3. use SystemLookAndFeel, or
      4. move resetChoosableFileFilters() before showOpenDialog().

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                rupashka Pavel Porvatov (Inactive)
                Reporter:
                ndcosta Nelson Dcosta (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: