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

[macosx] awt.FileDialog doesn't respond appropriately for mac when selecting folders

XMLWordPrintable

    • b55
    • x86
    • os_x

        FULL PRODUCT VERSION :
        OpenJDK Runtime Environment (build 1.7.0-jdk7u4-b19-20120410)
        OpenJDK 64-Bit Server VM (build 23.0-b20, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        Mac OS 10.7 Lion

        EXTRA RELEVANT SYSTEM CONFIGURATION :
        Using OpenJDK-OSX-1.7-x64-u4-jdk-jdk7u4-b19 as the runtime.

        A DESCRIPTION OF THE PROBLEM :
        CAN NOT GET THE FOLDER NAME BY SETTING THE SYSTEM PROPERTY ...

        apple.awt.fileDialogForDirectories SET TO true.

        THE FILE DIALOG BUTTON STILL SAYS OPEN AS IF TO SELECT A FILE RATHER THAN A DIRECTORY. THIS FORCES USERS TO INSTEAD USE THE FILECHOOSER WHICH DOES NOT CONTAIN NATIVE BEHAVIORS MAC USERS EXPECT TO SEE IN THE FILE DIALOGS.


        ON APPLE JAVA 1.6 IT DOES WORK.

        REGRESSION. Last worked in version 6u31

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Compile and run src below.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        SHOULD HAVE A java.awt.FileDialog WITH A [CHOOSE] BUTTON TO SELECT A FOLDER
        ACTUAL -
        INSTEAD GET AN [OPEN] BUTTON TO ONLY SELECT FILES.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------

        import javax.swing.*;
        import java.awt.*;
        import java.awt.event.ActionEvent;
        import java.awt.event.ActionListener;

        public class SelectFolderFrame extends JFrame {

          public static void main(String[] args){
            new SelectFolderFrame();
          }

          public SelectFolderFrame(){

            this.setLayout(new FlowLayout());
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            JButton clickMe = new JButton("Click Me");
            clickMe.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                FileDialog chooser = new FileDialog(SelectFolderFrame.this, "Select Target Folder ");
                System.setProperty("apple.awt.fileDialogForDirectories", "true");
                chooser.setVisible(true);
                if (chooser.getDirectory() != null) {
                  String folderName = chooser.getDirectory();
                  folderName += chooser.getFile();

                  //CAN NOT GET THE FOLDER NAME BY SETTING THE SYSTEM PROPERTY.
                  //THE FILE DIALOG BUTTON STILL SAYS OPEN AS IF TO SELECT A FILE
                  //RATHER THAN A DIRECTORY.
                  //ON APPLE JAVA 1.6 IT DOES.
                }
              }
            });

            this.getContentPane().add(clickMe); this.pack();

            this.setVisible(true);

          }
        }

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

        CUSTOMER SUBMITTED WORKAROUND :
        USE A javax.swing.JFileChooser INSTEAD

              serb Sergey Bylokhov
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: