apple.awt.fileDialogForDirectories property not working. (original) (raw)

Marco Dinacci marco.dinacci at gmail.com
Mon May 28 07:36:31 PDT 2012


Hi,

the apple.awt.fileDialogForDirectories property is not honoured neither with OpenJDK nor with Oracle JDK 7u4. The following program will work with Java 6 but not with the above mentioned distributions:

import java.awt.FileDialog; import java.io.File; import javax.swing.JFrame;

public class FileDialogTest extends JFrame {

public String selectFolder() {
    FileDialog fd = new FileDialog(this, "Select Folder Test",

FileDialog.LOAD); fd.setDirectory(System.getProperty("user.home")); fd.setLocation(50,50); fd.setVisible(true);

    return fd.getFile();
}

public static void main(String[] args) {
    System.setProperty("apple.awt.fileDialogForDirectories", "true");

    FileDialogTest fdt = new FileDialogTest();
    String selectedFolder = fdt.selectFolder();

    System.out.println("The selected file was: " + selectedFolder);

    System.setProperty("apple.awt.fileDialogForDirectories", "false");
    System.exit(0);
}

}

The expected result is to be able to select a directory, the actual result is that the file chooser enter the directory.

The Apple documentation states:

By default, the AWT File Dialog lets you choose a file. Under certain circumstances, however, it may be proper for you to choose a directory instead. If that is the case, set this property to allow for directory selection in a file dialog.

The default value is false.

Shall I file a bug ?

Best, Marco



More information about the macosx-port-dev mailing list