Getting the frame in processing 3

edited June 2017 in Share Your Work

This is for myself. To avoid the next hell of java reflection and processing's private and protected pain.

import processing.awt.*;
import java.awt.Frame;
import java.lang.reflect.Field;
import processing.awt.PSurfaceAWT.SmoothCanvas;

void setup() {
  Frame frame = get_frame();

Frame get_frame() {
  Frame frame = null;
  try {
    Field f = ((PSurfaceAWT) surface).getClass().getDeclaredField("frame");
    frame  = (Frame) (f.get(((PSurfaceAWT) surface)));
  catch(Exception e) {
  return frame;
Sign In or Register to comment.