dcsimg
Applet with JFilechooser called from a Javascript blocks paint messages to the Browser.
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Zapata_Work
Posted On:   Thursday, December 6, 2007 09:51 PM

Untitled Page function SelectFiles_onclick() { var s = (document.applets[0].selectFiles()); alert(s); } ]]>]]> Hi, I am trying to create an applet that can: 1) be called from a Javascript 2) displays a file selection dialog for multi-selecting files 3) returns the selected filenames in a string to the JavaScript I am able to use doPrivileged to apply the necessary security context to launch a JFilechooser and return the filenames selected. However, When the JFilechooser dialog is visible and the user moves the dialog window around the HTML pages dose not receive any repaint messages. They seem to be blocked by the thread that launched the JFilechooser d   More>>
Untitled Page

Hi,


I am trying to create an applet that can:





  • 1) be called from a Javascript

  • 2) displays a file selection dialog for multi-selecting files

  • 3) returns the selected filenames in a string to the JavaScript



I am able to use doPrivileged to apply the necessary security context to launch a JFilechooser and return the filenames selected. However, When the JFilechooser dialog is visible and the user moves the dialog window around the HTML pages dose not receive any repaint messages. They seem to be blocked by the thread that launched the JFilechooser dialog and is probably blocking update events as the dialog is still visible.



I know I need some type of a message pump so the child thread can inform the parent thread and the browser to repaint. However, I don't know how to do this.



Please help.




CODE:



------Applet Code Begin:-----


import java.awt.Color;


import java.awt.Graphics;


import java.awt.AWTEvent;


import java.awt.event.AWTEventListener.*;


import java.awt.event.MouseMotionListener;


import java.awt.event.MouseEvent;


import java.io.File;


import java.util.Locale;


import java.util.MissingResourceException;


import java.util.Properties;


import java.util.ResourceBundle;


import java.util.Vector;


import javax.swing.JApplet;


import javax.swing.JButton;


import javax.swing.JComponent;


import javax.swing.JFileChooser;


import javax.swing.JOptionPane;



public class SampleApplet extends JApplet


{



boolean allowDirs=false;


boolean allowFiles=true;


boolean hidden=false;



File lastUserDir=null;




public void init()


{


}



public void start()


{


}



public void stop()


{


}



public String selectFiles()


{


String choosenFiles = null;


choosenFiles = new String((String)

java.security.AccessController.doPrivileged(


new java.security.PrivilegedAction()


{


public Object run()


{


String choosenFiles=new String();


JFilechooser fc = new JFilechooser();


fc.setFileSelectionMode(allowDirs ? (allowFiles ?

JFileChooser.FILES_AND_DIRECTORIES


: JFileChooser.DIRECTORIES_ONLY)


: JFileChooser.FILES_ONLY);


fc.setMultiSelectionEnabled(true);



int returnVal = fc.showOpenDialog(null);



if (returnVal == JFileChooser.APPROVE_OPTION)


{


choosenFiles = "The selected filesnames will be stuffed here";


}



return choosenFiles; //return whatever you want


}


}));


return choosenFiles;


}


};



------Applet Code End:-----



------Html Code Begin:-----










Click Test button to select files







------Html Code End:-----

   <<Less
About | Sitemap | Contact