Posts Tagged ‘Processing’

Resize event in Processing sketch

mercredi, février 3rd, 2021

Here is how to make the Processing window resizable AND get an event when the window is resized.

Tested with Processing 3.

// For resize event
import java.awt.Canvas;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentAdapter;


void setup() {
  surface.setResizable(true);

  ((Canvas)surface.getNative()).addComponentListener(new ComponentAdapter() {
    @Override public void componentResized(ComponentEvent e) {
      println("resized " + width + " " + height);
    }
  }
  );
}