United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-7161437 : [macosx] awt.FileDialog doesn't respond appropriately for mac when selecting folders

Details
Type:
Bug
Submit Date:
2012-04-13
Status:
Resolved
Updated Date:
2013-12-06
Project Name:
JDK
Resolved Date:
2012-09-05
Component:
client-libs
OS:
os_x
Sub-Component:
java.awt
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Backport:
Duplicate:
Relates:
Relates:
Relates:

Sub Tasks

Description
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

                                    

Comments
Testcase was added in JDK-8029382
                                     
2013-12-06
SUGGESTED FIX

http://hg.openjdk.java.net/jdk8/awt/jdk/rev/b41845694f39
                                     
2012-08-13
EVALUATION

I'm re-opening this CR to provide support for directory selection dialogs on the Mac in 7uX timeframe.
                                     
2012-05-30
EVALUATION

A patch has been submitted by Marco Dinacci (###@###.###) and already reviewed by Mike Swingler on macosx-port-dev@ mailing list:

http://mail.openjdk.java.net/pipermail/macosx-port-dev/2012-May/004314.html
                                     
2012-05-30



Hardware and Software, Engineered to Work Together