I am trying to display a Java Applet in a Java FX WebView. However, as far as I've been able to figure, it is not possible.
How can I accomplish this, without the Java FX WebView?
I have gotten this working before. I eventually gave up on JavaFX as a Java Applet for the video game i was making, due to performance issues, but it is still valid for many other purposes. Here is the config I used.
<html><head>
<SCRIPT src="http://java.com/js/dtjava.js"></SCRIPT>
<script>
function launchApplication(jnlpfile) {
dtjava.launch( {
url : 'MyGame.jnlp'
},
{
javafx : '2.2+'
},
{}
);
return false;
}
</script>
<script>
function javafxEmbed() {
dtjava.embed(
{
url : 'MyGame.jnlp',
placeholder : 'javafx-app-placeholder',
width : 1024,
height : 768
},
{
javafx : '2.2+'
},
{}
);
}
<!-- Embed FX application into web page once page is loaded -->
dtjava.addOnloadCallback(javafxEmbed);
</script>
</head><body>
<h2>Test page for <b>MyGame</b></h2>
<b>Webstart:</b> <a href='MyGame.jnlp' onclick="return launchApplication('MyGame.jnlp');">click to launch this app as webstart</a><br><hr><br>
<!-- Applet will be inserted here -->
<div id='javafx-app-placeholder'></div>
</body></html>
I used JNLP to do this. Here is my JNLP file.
<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0" xmlns:jfx="http://javafx.com" href="MyGame.jnlp">
<information>
<title>MyGame</title>
<vendor>Jose</vendor>
<description>Sample JavaFX 2.0 application.</description>
<icon href="C:\Users\jose\Dropbox\MyGame\java7\MyGame/MyGame.ico" />
<offline-allowed/>
</information>
<resources>
<jfx:javafx-runtime version="2.2+" href="http://javadl.sun.com/webapps/download/GetFile/javafx-latest/windows-i586/javafx2.jnlp"/>
</resources>
<resources>
<j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se"/>
<jar href="MyGame.jar" size="27670609" download="eager" />
</resources>
<applet-desc width="1024" height="768" main-class="com.javafx.main.NoJavaFXFallback" name="MyGame" >
<param name="requiredFXVersion" value="2.2+"/>
</applet-desc>
<jfx:javafx-desc width="1024" height="768" main-class="game.Game" name="MyGame" />
<update check="background"/>
</jnlp>
Hope this helps. Let me know if you have any follow up questions.
JavaFX Web View doesn't support applets so it won't work for you. You should consider another embedable browser like JCEF or JWebBrowser from NativeSwing or some other component
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With