Access to native directory chooser

Fabrizio Giudici Fabrizio.Giudici at tidalwave.it
Mon Oct 22 12:46:59 PDT 2012


On Mon, 22 Oct 2012 21:13:36 +0200, Sergey Bylokhov  
<Sergey.Bylokhov at oracle.com> wrote:

> Hi, Robert.
> This functionality was added to jdk and will be available in jdk 7u12  
> and 8
>
> 7161437 : [macosx] awt.FileDialog doesn't respond appropriately for mac  
> when selecting folders
> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7161437
>
> 22.10.2012 22:46, Robert Krüger wrote:
>> Hi,
>>
>> we are currently using the following workaround to get a native
>> directory chooser in our app:
>>
>>          try {
>>              System.setProperty("apple.awt.fileDialogForDirectories",  
>> "true");
>>              fileDialog.setVisible(true);
>>          } finally {
>>              System.setProperty("apple.awt.fileDialogForDirectories",  
>> "false");
>>          }
>>
>> Is there anything other than JNI possible with JDK7?
>>
>> Thanks in advance,
>>
>> Robert

Probably there's something I'm not understanding, but I've been running a  
native Mac OS X filechooser since JDK 7u4 using Quaqua with this code:

     private void runMacOSX (final @Nonnull Component parent)
       {
         final JFileChooser fileChooser = createFileChooser();

         JSheet.showSaveSheet(fileChooser, parent, new SheetListener()
           {
             @Override
             public void optionSelected (final @Nonnull SheetEvent event)
               {
                 if (event.getOption() == APPROVE_OPTION)
                   {
                     onFileSelected(fileChooser.getSelectedFile().toPath());
                   }
               }
           });
       }

     @Nonnull
     private JFileChooser createFileChooser()
       {
         final JFileChooser fileChooser = new JFileChooser();
         fileChooser.setDialogType(OPEN_DIALOG);
         fileChooser.setFileSelectionMode(type);
         return fileChooser;
       }


I rather have problems with the Sheet rendering, which is not natively  
rendered due to a bug:

http://java.net/jira/browse/QUAQUA-160



-- 
Fabrizio Giudici - Java Architect @ Tidalwave s.a.s.
"We make Java work. Everywhere."
http://tidalwave.it/fabrizio/blog - fabrizio.giudici at tidalwave.it


More information about the macosx-port-dev mailing list