Fandom

Planet JFX

Use any swing component

118pages on
this wiki
Add New Page
Talk0 Share

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.

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

Also on Fandom

Random Wiki