JavaFX in JApplet and Java7 - maybe?

Is it possible to enrich Swing-based JApplet (running in a web browser) with JavaFX content that works for Java7 clients? I tried the following things, but to no avail:

a) Swing JApplet : if I try to add a JFXPanel to a JApplet, I get java.lang.ClassNotFoundException: javafx.embed.swing.JFXPanel at runtime.

b) Swing JApplet, including the javafx_version parameter (version 2.2+, see the generated APPLET tag when using the dtjava.embed () deployment toolkit): adding a JFXPanel to the JApplet results in java.lang.ClassCastException: SwingInterop cannot be passed to javafx.application.Application at runtime.

c) AppleFX Applet (javafx.application.Application) . It seems that the swing content can only be displayed in the new JFrame (as shown in the official Oracle example at http://www.oracle.com/technetwork/java/javase/overview/javafx-samples-2158687.html ) JavaFX applet (javafx.application.Application). The SwingNode introduced with Java8 would obviously be the way to go, but I did not find a reliable alternative for Java7.

Is there a way to get option a) by running the addition of jfxrt.jar to the classpath (like option b), obviously doing something)?

+4
source share
1 answer

Oracle JavaFX Swing Java 7.

.

, jfxrt.jar ( , ).


Oracle, .

JavaFX Ant Swing JavaFX ( toolkit="swing"):

<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"      
        uri="javafx:com.sun.javafx.tools.ant"
        classpath="${javafx.sdk.path}/lib/ant-javafx.jar"/>

<fx:jar destfile="dist-web/ColorfulCircles.jar">
    <fx:application refid="myapp"/>
    <fileset dir="build/classes/">
        <include name="**"/>
    </fileset>
</fx:jar>

<fx:deploy width="800" height="600" outdir="dist-web" 
        outfile="SwingInterop">
    <fx:info title="Swing Interop"/>
    <!-- Mark application as a Swing app -->
    <fx:application id="myapp" 
            mainClass="swinginterop.SwingInterop"
            toolkit="swing"/>
    <fx:resources>
        <fx:fileset dir="dist-web" includes="SwingInterop.jar"/>
    </fx:resources>
</fx:deploy> 

JavaFX, JavaFX, jnlp, jfx:

<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0"
        xmlns:jfx="http://javafx.com"
        href="SwingAppWithJavaFXContent.jnlp"
        ...>
     ....
    <resources>
        <j2se version="1.7.0_06+" 
            href="http://java.sun.com/products/autodl/j2se"/>
        <jfx:javafx-runtime version="2.1+" 
            href="http://javadl.sun.com/webapps/download/GetFile/
                    javafx-latest/windows-i586/javafx2.jnlp"/>
    </resources>
    ...
</jnlp> 

html Java JavaFX :

<html>
    <head>
            <SCRIPT src="http://java.com/js/dtjava.js"></SCRIPT>
            <script>
                function launchApplication(jnlpfile) {
                dtjava.launch(
                    { url : jnlpfile },
                    {
                        javafx : '2.2+',
                        toolkit: 'swing'
                    },
                    {}
                );
                return false;
            }
        </script>
    </head>
    <body>
        <h2>Test page</h2>
        <a href='SampleApp.jnlp' 
        onclick="return launchApplication('SampleApp.jnlp');">Click</a> 
        to launch test app.
    </body>
</html>

JavaFX (JFXPanel) JApplet .

, ( , ), JFXPanel javadoc .


JavaFX Swing Applet . JavaFX "SwingInterop". SwingInterop "JDK 8 Demos and Samples" Java download. Java 7 Java 7.

+2

Source: https://habr.com/ru/post/1534228/


All Articles