Wikia

Planet JFX

Use any swing component

Talk0
119pages on
this wiki

PurposeEdit

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.

CodeEdit

SwingWidget.fx
Code
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.

UsageEdit

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.

WidgetTest.fx
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() {
               System.exit(0);
       }
       content: SwingWidget {
               swingComponent: new JTree()
       }
       visible: true
       title: "WTF, the Widget Test Framework"
}
SwingWidgetExample

Around Wikia's network

Random Wiki