How to stop JFrame from closing after Processing sketch is closed

edited November 2017 in Questions about Code

So, I'm using Processing in a swing app and I'm wondering if there is a way to stop a JFrame from closing after the Processing sketch is stopped. This code will demonstrate my problem:


Frame frame;
void setup(){
  frame = new Frame();
  size(300, 300);

void draw(){



import javax.swing.*;

class Frame extends JFrame {
  public Frame(){
    this.setSize(250, 250);

    this.setVisible( true );

I understand that in this case, Frame is a nested class of JFrameTest in Java. In my app, this isn't the case. I use the PApplet.main method to start Processing sketches but I'm curious if there is a solution from with the PDE!


  • edited November 2017

    Thanks for pointing me to that, @GoToLoop.

    In case anyone is curious, this is what the file should look like!


    Frame frame;
    void setup(){
      size(300, 300, P2D);
      frame = new Frame(this);
    void draw(){
    void stopJFrameFromClosing() {
      // Get OpenGL window
      com.jogamp.newt.opengl.GLWindow newtCanvas = (com.jogamp.newt.opengl.GLWindow) surface.getNative();
      // Remove listeners added by Processing
      for (com.jogamp.newt.event.WindowListener l : newtCanvas.getWindowListeners())
        if (l.getClass().getName().startsWith("processing"))
      // Set on close action to dispose window

    Thanks, @quark!

  • Is that proper? If I close the Frame object, it crashes. If I close the sketch, then the frame, you get a nasty messages: dead thread. Wouldn't one override their exit functions? Now, you might have re-defined your Frame class to handle the current sketch.


Sign In or Register to comment.