How can I add a swingNode
to a specific
pane?
I'm actually trying to add a JPanel
that loads an applet to the transparent area of the following and I'm not sure how to do it.
SwingNode
is a javafx scene node and can be added to any javafx scene layouts.
To add a JPanel to a Pane and display it on JavaFX stage:
A very simple code sample to show how you can add it to a Pane is (from SwingNode
Javadoc):
public class SwingNodeExample extends Application {
@Override
public void start(Stage stage) {
final SwingNode swingNode = new SwingNode();
createAndSetSwingContent(swingNode);
Pane pane = new Pane();
pane.getChildren().add(swingNode); // Adding swing node
stage.setScene(new Scene(pane, 100, 50));
stage.show();
}
private void createAndSetSwingContent(final SwingNode swingNode) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JPanel panel = new JPanel();
panel.add(new JButton("Click me!"));
swingNode.setContent(panel);
}
});
}
public static void main(String[] args) {
launch(args);
}
}