Here is a reusable bit of code that provides a quick wrapper for a Swing component that allows it to be used inside of a JavaFX Widget hierarchy.

This solution was derived from this thread on the forums.


package a.b.c;

import javafx.ui.*;
import javax.swing.JComponent;

class SwingWidget extends Widget {
       attribute swingComponent: JComponent;

operation SwingWidget.createComponent():<<javax.swing.JComponent>> {
    return swingComponent;

If you need more details on making reusable JavaFX code, be sure to read Referencing other JavaFX files.


Here is a quick example of usage of SwingWidget. Note that the data provided in the tree comes from the default tree model, and not something special in JavaFX.

Code Preview
package a.b.c;

import javafx.ui.*;
import javafx.ui.canvas.*;
import java.lang.System;
import javax.swing.JTree;
import a.b.c.SwingWidget;

Frame {
       onClose: operation() {
       content: SwingWidget {
               swingComponent: new JTree()
       visible: true
       title: "WTF, the Widget Test Framework"

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.