Platinum Partner
java,javafx,client-side

Calling JavaFX From Java

If you searched for a solution to embed JavaFX components in Swing you won’t have success with a version which is officially supported.

But as always there are workarounds like the one from Josh Marinacci. So far I can’t get it working it gives me:

java.lang.NoSuchMethodException: MyScene.javafx$run$(com.sun.javafx.runtime.sequence.Sequence)

The simple workaroung is now the following (Java Side)

JXScene scene = new JXScene();
scene.setScene(new de.timefinder.planner.widgets.SwingHook());
// ... or create the class indirectly
// Class clazz = Class.forName("de.timefinder.planner.widgets.SwingHook");
// scene.setScene(clazz.newInstance());

// now copy parts of the code from Josh's article
class JXScene extends JComponent {
    public void setScene(Object scene) {
        String helperName = "com.sun.javafx.scene.JSGPanelSceneImpl";
        FXClassType type = FXContext.getInstance().findClass(helperName);
        FXObjectValue panelSceneImpl = type.allocate();
        panelSceneImpl.initVar("scene", FXLocal.getContext().mirrorOf(scene));
        panelSceneImpl.initialize();

        FXValue jsgPanelV = type.getVariable("jsgPanel").getValue(panelSceneImpl);
        JComponent jsgPanel = (JComponent) ((FXLocal.ObjectValue) jsgPanelV).asObject();
        add(jsgPanel, BorderLayout.CENTER);
    }

    public JXScene() {
        setLayout(new BorderLayout());
    }
}

And use the same JavaFX side snippet:

public class SwingHook extends Scene {
    init {
        content = MainWindowContents{}.getContents()
    }
}

From http://karussell.wordpress.com/

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}