apple.awt.fileDialogForDirectories property not working.

Mike Swingler swingler at apple.com
Tue May 29 10:00:22 PDT 2012


Sandboxing, by it's nature, prevents access to the user's general home directory. It restricts access to all but a very narrow per-app directory hidden within the user's home directory.

The viable alternative for the Swing API is to simply delegate to the AWT dialog (or a customized native dialog which better implements the Swing JFileChooser features) when run under sandboxing. A truly TCK compliant JFileChooser is simply not possible in the sandboxed environment - or at least in a form that will go anywhere interesting on the file system.

Regards,
Mike Swingler
Apple Inc.

On May 29, 2012, at 6:52 AM, niagarasoft20-macosxportdev at yahoo.com wrote:

> Marco,
> 
> Please file this as a  bug . The user should be able to choose their own directory on a mac when using the JFileChooser. If this is the case, it's pretty serious problem.
> 
> 
> Regards
> Mike
> 
> 
> 
> 
>> ________________________________
>> From: Marco Dinacci <marco.dinacci at gmail.com>
>> To: "niagarasoft20-macosxportdev at yahoo.com" <niagarasoft20-macosxportdev at yahoo.com> 
>> Cc: macosx-port-dev Port OS X <macosx-port-dev at openjdk.java.net> 
>> Sent: Monday, May 28, 2012 11:39 AM
>> Subject: Re: apple.awt.fileDialogForDirectories property not working.
>> 
>> 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