Processing 3 nested inside JavaFX


I have a probem with nesting Processing inside JavaFX. I've got a heavy-GUI application which I would not like to rewrite in Swing neither split into parts and add to sketch itself. Reading the forum I was able to find out how to extract sketch canvas and put it inside JPanel:

public void initialize(SwingNode swingNode) {
        this.swingNode = swingNode;

        PSurface pSurface = this.initSurface();
        pSurface.setSize(640, 360);
        PSurfaceAWT.SmoothCanvas smoothCanvas = (PSurfaceAWT.SmoothCanvas) pSurface.getNative();

        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());
        panel.add(smoothCanvas, BorderLayout.CENTER);
        panel.setSize(640, 360);



    public void settings() {
        size(640, 360);

    public void setup() {

    public void draw() {
        ellipse(56, 46, 55, 55);

The problem is that when I put the JPanel on the SwingNode - JPanel does not render or an exception is thrown:

Exception in thread "Animation Thread" java.lang.IllegalArgumentException: Width (0) and height (0) cannot be <= 0 at sun.awt.image.SunVolatileImage.<init>( at sun.java2d.pipe.hw.AccelTypedVolatileImage.<init>( at sun.java2d.d3d.D3DGraphicsConfig.createCompatibleVolatileImage( at$VIWindowPainter.getBackBuffer( at at at sun.java2d.d3d.D3DGraphicsConfig.flip( at at java.awt.Component$FlipBufferStrategy.flip( at java.awt.Component$ at processing.awt.PSurfaceAWT.render( at processing.awt.PSurfaceAWT$12.callDraw( at processing.core.PSurfaceNone$

Has someone managed to successfully embed the sketch inside JavaFX GUI?

Sign In or Register to comment.