title: How to embed a PApplet in javafx?
body: <p>So I got my Processing code working in java. But now I want to embed it in JavaFX for my GUI. How can I do so?
  I tried using the following code but it does not seem to work.</p>
  
  <pre><code> package testprocessing;
  import javafx.application.Application;
  import javafx.embed.swing.SwingNode;
  import javafx.scene.*;
  import javafx.scene.paint.Color;
  import javafx.stage.Stage;
  
  import javax.swing.JApplet;
  import javax.swing.SwingUtilities;
  import java.awt.Dimension;
  
  import java.util.concurrent.*;
  import processing.core.*;
  
  public class JavaFxApplet extends Application {
      private PApplet applet = new MyProcessingSketch();
      private Dimension appletSize;
  
      @Override public void init() throws ExecutionException, InterruptedException {
          applet.init();
  
          FutureTask&lt;Dimension&gt; sizingTask = new FutureTask&lt;&gt;(() -&gt;
              applet.getRootPane().getPreferredSize()
          );
          SwingUtilities.invokeLater(sizingTask);
          appletSize = sizingTask.get();
      }
  
      @Override public void start(Stage stage) {
          final SwingNode swingNode = new SwingNode();
          SwingUtilities.invokeLater(() -&gt;
              swingNode.setContent(applet.getRootPane())
          );
  
          stage.setScene(
              new Scene(
                  new Group(swingNode),
                  appletSize.getWidth(), appletSize.getHeight(),
                  Color.BLACK
              )
          );
          stage.show();
      }
  
      @Override public void stop() {
          applet.stop();
          applet.destroy();
      }
  
      public static void main(String[] args) {
           launch(args);
       }
  }
  </code></pre>
  
  <p>I get error at getRootPane(). Can you suggest an alternative for it?</p>