apple.awt.fileDialogForDirectories property not working.

Marco Dinacci marco.dinacci at gmail.com
Mon May 28 08:39:36 PDT 2012


Hi,

JFileChooser doesn't use a native dialog so it won't be able to list
any directory except I guess for the container
(~/Library/Containers/myapp/Data) and any special directories listed
in the entitlements file.

I just bundled and signed an app with the code below  the result is a
JFileChooser listing my home directory and not showing any icon:

mport javax.swing.JFrame;
import java.io.File;
import javax.swing.JFileChooser;

public  class FileChooserTest extends JFrame {

    public String selectFolder() {
      JFileChooser chooser = new JFileChooser(System.getProperty("user.home"));
      chooser.showOpenDialog(this);
      //chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
      return chooser.getSelectedFile().getAbsolutePath();

    }

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

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

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

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

}


Best,
Marco


On 28 May 2012 16:23, niagarasoft20-macosxportdev at yahoo.com
<niagarasoft20-macosxportdev at yahoo.com> wrote:
> Hi Marco,
>
> Can you clarify the sandbox issue?
>
> Mike
>
> It's worse than that, the JFileChooser won't work if the application
> is in a sandbox so I can't use it.
>
> Which leaves as only solution hacking the awt.FileDialog...
>


More information about the macosx-port-dev mailing list