This class is used to embed a Swing content into a JavaFX application.
The content to be displayed is specified with the setContent method
that accepts an instance of Swing JComponent. The hierarchy of components
contained in the JComponent instance should not contain any heavyweight
components, otherwise SwingNode may fail to paint it. The content gets
repainted automatically. All the input and focus events are forwarded to the
JComponent instance transparently to the developer.
Here is a typical pattern which demonstrates how SwingNode can be used:
public class SwingFx extends Application {
@Override
public void start(Stage stage) {
final SwingNode swingNode = new SwingNode();
createAndSetSwingContent(swingNode);
StackPane pane = new StackPane();
pane.getChildren().add(swingNode);
stage.setScene(new Scene(pane, 100, 50));
stage.show();
}
private void createAndSetSwingContent(final SwingNode swingNode) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
swingNode.setContent(new JButton("Click me!"));
}
});
}
public static void main(String[] args) {
launch(args);
}
}
extends