Java Reference
In-Depth Information
You want to embed some standard Java Swing code into a JavaFX application.
Solution
Use a SwingNode to embed the Swing content into the application. In the following
simple JavaFX application, a front-end is created with JavaFX, and a Swing JLabel
component is embedded in it.
public class Recipe02_09 extends Application {
@Override
public void start(Stage primaryStage) throws
Exception {
final SwingNode swingNode = new SwingNode();
createSwingContent(swingNode);
StackPane pane = new StackPane();
pane.getChildren().add(swingNode);
primaryStage.setScene(new Scene(pane, 100, 50));
primaryStage.show();
}
private void createSwingContent(final SwingNode
swingNode) {
SwingUtilities.invokeLater(() -> {
swingNode.setContent(new JLabel("Hello
Swing"));
});
}
/**
* @param args the command-line arguments
*/
public static void main(String[] args) {
launch(args);
}
Search WWH ::




Custom Search