Note that there are some explanatory texts on larger screens.

plurals
  1. POJava applet not visible in Chrome
    text
    copied!<p>I'm running into some kind race condition in a Java applet, peculiar to Google Chrome (win xp). I'm writing the <code>&lt;applet&gt;</code> tag into a popup window.</p> <p>The problem is characterised by: </p> <ol> <li>The applet <strong>always shows fine in MS IE and Firefox</strong>.</li> <li>In Chrome The applet only displays about <strong>50%</strong> of the time.</li> <li>When it doesn't display, the applet actually appears to be silently running perfectly from the Java console! No errors!</li> <li>The <code>JApplet</code>'s <code>init()</code> and <code>start()</code> methods are always called.</li> <li><code>isShowing()</code> and <code>isDisplayable()</code> always return <code>true</code>, even when the applet does not show.</li> <li>When it doesn't show, the <code>paint()</code> method <strong>isn't</strong> called.</li> <li>When the applet doesn't show, a transparent rectangular area (of the window background colour) where the applet should have been can be noticed when the text in the window is selected. From this I take it that the applet region is correctly placed in the window.</li> </ol> <h2>My code:</h2> <p>MyApplet.java</p> <pre><code> package mypackage; public class MyApplet extends JApplet { public void init(){ super.init(); getContentPane().add(new JLabel("Hello"), BorderLayout.CENTER); System.out.println("init ok"); } public void start() { super.start(); System.out.println("s parent:"+this.getParent()); System.out.println("s disp:"+this.isDisplayable()); System.out.println("s showing:"+this.isShowing()); } public void paint(Graphics g){ System.out.println("painting"); super.paint(g); } } </code></pre> <p>test.html</p> <pre><code>&lt;HTML&gt; &lt;SCRIPT language='JavaScript'&gt; var jarpath='./myjar.jar'; var classname='mypackage.MyApplet'; function opentest(){ applet=window.open('', '', "height=420,width=620"); applet.document.write( '&lt;html&gt;&lt;body&gt;'+ '&lt;OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"'+ 'width=600 height=400&gt;'+ '&lt;param name=code value="'+classname+'"&gt;'+ '&lt;param name=archive value="'+jarpath+'"&gt;'+ '&lt;param name=type value="application/x-java-applet;version1.3"&gt;'+ '&lt;COMMENT&gt;'+ '&lt;EMBED code="'+classname+'" archive="'+jarpath+'" ' + 'type="application/x-java-applet;version=1.3" ' + 'width=600 height=400 ' + '&gt;'+ '&lt;NOEMBED&gt;' + 'unavailable'+ '&lt;/NOEMBED&gt;'+ '&lt;/EMBED&gt;' + '&lt;/COMMENT&gt;' + '&lt;/OBJECT&gt;'+ '&lt;/body&gt;&lt;/html&gt;' ); } &lt;/SCRIPT&gt; &lt;BODY&gt; Click here to open &lt;A onclick="opentest()"&gt;Test&lt;/A&gt; &lt;/BODY&gt; &lt;/HTML&gt; </code></pre> <h2>Output from console</h2> <p>50% of the time I click on 'Test', the new window contains the 'Hello' label. The other 50% of the time, the window is blank as described. The console output seems identical when the applet loads and doesn't load. It seems blameless!</p> <pre><code>security: property package.access value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio. security: property package.access new value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.javaws security: property package.access value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.javaws security: property package.access new value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.javaws,com.sun.deploy security: property package.access value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.javaws,com.sun.deploy security: property package.access new value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.javaws,com.sun.deploy,com.sun.jnlp security: property package.definition value null security: property package.definition new value com.sun.javaws security: property package.definition value com.sun.javaws security: property package.definition new value com.sun.javaws,com.sun.deploy security: property package.definition value com.sun.javaws,com.sun.deploy security: property package.definition new value com.sun.javaws,com.sun.deploy,com.sun.jnlp security: property package.access value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.javaws,com.sun.deploy,com.sun.jnlp security: property package.access new value sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.javaws,com.sun.deploy,com.sun.jnlp,org.mozilla.jss security: property package.definition value com.sun.javaws,com.sun.deploy,com.sun.jnlp security: property package.definition new value com.sun.javaws,com.sun.deploy,com.sun.jnlp,org.mozilla.jss basic: Added progress listener: sun.plugin.util.GrayBoxPainter$GrayBoxProgressListener@137c60d basic: Plugin2ClassLoader.addURL parent called for file:/E:/Java/eclipse/MyApplet/myjar.jar network: Cache entry not found [url: file:/E:/Java/eclipse/MyApplet/myjar.jar, version: null] network: Cache entry not found [url: file:/E:/Java/eclipse/MyApplet/myjar.jar, version: null] basic: Applet loaded. basic: Applet resized and added to parent container basic: PERF: AppletExecutionRunnable - applet.init() BEGIN ; jvmLaunch dt 145396 us, pluginInit dt 331540 us, TotalTime: 476936 us init ok basic: Applet initialized basic: Removed progress listener: sun.plugin.util.GrayBoxPainter$GrayBoxProgressListener@137c60d basic: Applet made visible basic: Starting applet basic: completed perf rollup s parent:sun.plugin2.main.client.PluginEmbeddedFrame[frame0,0,0,600x400,invalid,layout=java.awt.BorderLayout,title=,resizable,normal] s disp:true s showing:true basic: Applet started basic: Told clients applet is started </code></pre> <h2>Update</h2> <p>Thanks to Ates, trying the following timeout makes the Applet appear correctly <strong>100% of the time</strong>.</p> <pre><code>function opentest(){ applet=window.open('', '', "height=420,width=620"); setTimeout(function () { applet.document.write( ... ); } , 1000 ); } </code></pre> <ul> <li>As Ates mentions, we now see that our popup window doesn't like immediate <code>document.write</code>s!</li> <li>Is this correct behaviour? Am I supposed to wait for some signal before writing to a document?</li> <li>Should I be going about this a different way? Can I add some kind of listener to know when it is safe to call <code>document.write()</code>?</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload