My problem is as follows: I have a JApplet embedded into the HTML page and a form button with JS call of applet’s public method:
<input id="btnAppletSelectFiles" type="button" value="Select Files"
onclick="document.appletExcelUploader.SelectFiles();" />
in my JApplet I have FileChooser like:
public class ExcelUploader extends JApplet {
private JFileChooser fc = new JFileChooser();
// Some stuff
}
And I’m writing code like this in my applets’ public method:
public void SelectFiles() {
int retVal = fc.showOpenDialog(ControlsPanel.this);
if (retVal == JFileChooser.APPROVE_OPTION) {
for (File file : fc.getSelectedFiles()) {
System.out.println(file.getName());
}
}
}
And so when HTML button is clicked, File Dialog is shown normally, I can surf directories and check files, but I cannot press Open or OK button – I click it but dialog stays.
I think that I have a problem with threads – that I still somehow do this in “HTML and JS” Thread and not in my applets’ GUI thread or event dispatch thread.
How to fix the problem?
Methods in trusted applets that are called from JavaScript are no longer trusted because Java cannot account for all the code frames in the stack. To rectify the problem, use one of the
AccessController.doPrivileged(..)overloaded methods.