JXSceneA Java class that allows embedding a javafx scene in java/swing. It allows communication between the swing and javafx side. This class was originally created by Richard Bair and Jasper Potts and re-implemented for version javafx1.2 For more examples and documentation check out this blog post: http://blogs.sun.com/javafx/entry/how_to_use_javafx_in This implementation brings up some minor additions not present on the original JXScene. Differences from the original JXScene
public void setScene(String sceneClassName, Map<String, Object> initVars)Just pass in a map containing the <name of variable> - <value> pairs. ExampleJavaFX Object, extends Scene and implements Talker (JavaInterface).
public class YourJavaFXScene extends Scene, Talker {
public override function talk(msg:String):Void {...}
}
Java side
public class TheFrame extends javax.swing.JFrame {
public TheFrame() {
final JXScene<Talker> jxScene = new JXScene<Talker>();
jxScene.setScene("com.yourproject.YourJavaFXScene"); // the name of your main JavaFX class
add(jxScene); // add the scene your swing scene
com.sun.javafx.runtime.Entry.deferAction( new Runnable() {
public void run() {
jxScene.getScene().talk("Hi There");//generics in action.
}
});
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new TheFrame().setVisible(true);
}
});
}
}
Requirements
Note however that we were unable to reproduce video on vista and windows 7 - the jvm crashes without giving any error information. But it does work on windows xp. Final NotesEmbedding Javafx in a swing app is not currently officially supported.The next release of JavaFX will make this much harder to accomplish as it will no longer be dependent on AWT/Swing, the underlying graphics engine will be replaced.However there are plans to officially support embedding javafx in a swing app and the next release codenamed Soma will have some pre requisite work done on that matter. It seems that javafx video doesn't work with this approach on windows 7 and windows vista. On windows XP it works fine. 1495 Views |