Skip to main content

Using compiled JavaFX in a Swing applet

1 reply [Last post]
Joined: 2008-03-13


I have an existing Swing applet that I'm trying to add JavaFX support to.

I already have it working with interpreted JavaFX, via the Java6 Scripting Engine and adding the JavaFX Canvas's component to a JPanel, and that's fine for simple scripts, but for better performance and a simple way to deploy and run multi-script JavaFX code I'd like to use compiled JavaFX as well.

I have a JavaFX script that defines a class, which I instantiate from my Swing applet via reflection - that works fine. I then call a method on the class to return a JComponent to me so that I can add it to my Swing UI, and that's where the problem starts.

I intended to have the JavaFX class return the result of the Canvas.getComponent() method but I cannot create a Canvas object from within my compiled JavaFX class. At runtime I see the following Exception;

Caused by: java.lang.NoSuchMethodError: javafx.ui.Canvas.(Z)V
at javafxtest.altiotest.setupCanvas$impl(altiotest.fx:77)
at javafxtest.altiotest.setupCanvas(altiotest.fx:28)
at javafxtest.altiotest.getControlComponent$impl(altiotest.fx:101)

My JavaFX code for creating a Canvas (and also Frame, Text or FlowPanel I have discovered) which works fine when I run the compiled JavaFX file from the command-line, does not work at runtime in the Swing applet.

Is this some kind of Applet sandbox permission issue, or something simpler? I am running the applet via a JNLP file, and including the javafxrt.jar and scenario.jar files, so everything is hooked up correctly and I'm at a loss to figure out what's going on.

Any help would be appreciated.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2008-03-13

Well, I tried again yesterday and it all seems to work fine in the JavaFX preview SDK, so I must have been trying to do something on the bleeding edge and fell off ;-)