dcsimg
Building a directory applet chooser (JFileChooser)
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Francois_Chiausa
Posted On:   Friday, April 24, 2009 06:43 AM

Hello, I'm having a hard time trying to make my applet working. I build an applet launching the swing JFileChooser component. My applet is working on some PCs. On others PCs this applet is making the browther not stable (refresh matters, blank applet window + blank java debug window like if the jvm was crashed). For information : I do sign my applet with jarsigner and the browther correctly ask if I want to accept the certificate After many tries I figure out that the JFileChooser is the cause of all my browthers matters. I try to find a solution but I not able to find a way to make a directory chooser without the swing    More>>

Hello,



I'm having a hard time trying to make my applet working.
I build an applet launching the swing JFileChooser component.


My applet is working on some PCs. On others PCs this applet is making the browther not stable (refresh matters, blank applet window + blank java debug window like if the jvm was crashed).



For information : I do sign my applet with jarsigner and the browther correctly ask if I want to accept the certificate



After many tries I figure out that the JFileChooser is the cause of all my browthers matters.



I try to find a solution but I not able to find a way to make a directory chooser without the swing JFileChooser component, the AWT FileDialog component doesn't have the DIRECTORY_ONLY option. And it seams that we can not use the swt component as an applet.



Please is someone having an idea on how I can make this component working in an applet ?




My applet code



import javax.swing.JApplet;

import javax.swing.JFileChooser;





public class FileApplet extends JApplet {



  public void init() {

    /*

     * peut etre remplacé par un fichier applet.policy : ajouter : grant

     * {permission java.security.AllPermission;};

     */

    System.out.println("FileApplet.init() : Applet loaded");

    System.setSecurityManager(null);

    System.out.println("FileApplet.init() : Changing sandbox security");  

  }



  public String fileChooser() {

    System.out.println("FileApplet.fileChooser() : Applet function called");

    JFileChooser jfc = new JFileChooser();

    // limit the chooser only on folders

    jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    int file = jfc.showOpenDialog(FileApplet.this);

    // I check that the user validate a folder

    if (file == JFileChooser.APPROVE_OPTION) {

      // I retrieve the absolute path

      String path = jfc.getSelectedFile().getAbsolutePath();

      System.out.println("Selected path : " + path);

      return path;

    }

    // If the user clicked on the "cancel" button

    System.out.println("No path selected user clicked on Cancel button");

    return "";

  }



}



My HTML page calling my applet









  

    

     codebase = "."

     code = "FileApplet.class"

     archive = "FileApplet.jar"

     name = "FileApplet"

     width = "0"

     height = "0"

     hspace = "0"

     vspace = "0"

     align = "top"

     MAYSCRIPT

     >

    

    


     fileChooser

  







Regards,
Francois    <<Less

Re: Building a directory applet chooser (JFileChooser)

Posted By:   Francois_Chiausa  
Posted On:   Saturday, April 25, 2009 01:38 PM

I figure out what was the bug. My matters are not comming from the applet but from the JFileChooser.
The JFileChooser has a bug in the java 1.6 release and on some windows vista as well as XP it can't be display.

If some one has an idea on how to use an other component to select a directory I will be pleased to have the tip.

Regards,

Francois
About | Sitemap | Contact