JDK-7161437 : [macosx] awt.FileDialog doesn't respond appropriately for mac when selecting folders
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x
  • CPU: x86
  • Submitted: 2012-04-13
  • Updated: 2013-12-06
  • Resolved: 2012-09-05
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 Availabitlity Release.

To download the current JDK release, click here.
JDK 7 JDK 8
7u40Fixed 8 b55Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
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 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

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