error on CP5 since update to processing3

Hello guys,

since I updated to processing3, I tried to run a program I wrote last year. the program worked perfectly, but now I get error on my controlP5. It always sais "The method add(Component) in the type Container is not applicable for the arguments (ControlP5frame.controlFrame)" When I open a example from the CP5library where the same code is used, ControlP5Frame by Andreas Schlegel, it gives the same error.

I also redownloaded the library with no results. I really hope someone can help me out. Thanks

This is the example in the library. The error I get is on f.add(p) in the method addControlFrame(..)

import java.awt.Frame; import java.awt.BorderLayout; import controlP5.*;

private ControlP5 cp5;

ControlFrame cf;

int def;

void setup() { size(400, 400); cp5 = new ControlP5(this);

// by calling function addControlFrame() a // new frame is created and an instance of class // ControlFrame is instanziated. cf = addControlFrame("extra", 200,200);

// add Controllers to the 'extra' Frame inside // the ControlFrame class setup() method below.


void draw() { background(def); }

ControlFrame addControlFrame(String theName, int theWidth, int theHeight) { Frame f = new Frame(theName); ControlFrame p = new ControlFrame(this, theWidth, theHeight); f.add(p); p.init(); f.setTitle(theName); f.setSize(p.w, p.h); f.setLocation(100, 100); f.setResizable(false); f.setVisible(true); return p; }

// the ControlFrame class extends PApplet, so we // are creating a new processing applet inside a // new frame with a controlP5 object loaded public class ControlFrame extends PApplet {

int w, h;

int abc = 100;

public void setup() { size(w, h); frameRate(25); cp5 = new ControlP5(this); cp5.addSlider("abc").setRange(0, 255).setPosition(10,10); cp5.addSlider("def").plugTo(parent,"def").setRange(0, 255).setPosition(10,30); }

public void draw() { background(abc); }

private ControlFrame() { }

public ControlFrame(Object theParent, int theWidth, int theHeight) { parent = theParent; w = theWidth; h = theHeight; }

public ControlP5 control() { return cp5; }

ControlP5 cp5;

Object parent;



  • edited April 2016 Answer ✓

    Funny enough I was just about to come here to talk about the same thing, but it seems like I managed to find a solution.

    Here's what I understand so far: Processing 3 doesn't work with the Frame class anymore. So this whole code is basically useless now.

    I found some extra-window code written by @codeanticode and I've managed to get it running with ControlP5 like this. The trick is to use the .plugto() method and pass the main PApplet to the new one as a parent. This way the buttons are still drawn in the new window but you can use a variable with the same name to store the values in.

    Disclaimer: I just fiddle and get things to work. There might be a better, more optimal way.

    import controlP5.*;
    PWindow win;
    ControlP5 cp5;
    public float boxValue = 23;
    public void settings() {
      size(320, 240);
    void setup() { 
      cp5 = new ControlP5(this);
      win = new PWindow(this);
    void draw() {
      background(255, 0, 0);
      rect(10, 10, boxValue, 10);
    void mousePressed() {
      println("mousePressed in primary window");
    class PWindow extends PApplet {
      ControlP5 cpExtra;
      PApplet parent;
      PWindow(PApplet app) {
        PApplet.runSketch(new String[] {this.getClass().getSimpleName()}, this);
        cpExtra = new ControlP5(this);
        parent = app;
      void settings() {
        size(500, 200);
      void setup() {
      void draw() {
      void mouseReleased() {
        println("mousePressed in secondary window "+boxValue);
      void boxValue(){
        //do something when numberbox is changed
        //boxValue = cp5.getController("boxValue").getValue();
  • wow thank you very much!

  • Couple of things I've discovered that might interest you or future readers:

    • this new window doesn't initiate the sketchPath field properly, causing functions like loadStrings(filename) to fail since it looks for filename in the sketchfolder.

    My solution is to pass the string of the sketchpath in the constructor of the new PWindow. You can automatically get this by calling sketchPath(). You can then override this method in your new PWindow so it gives you the correct result.

    • you can make the window disappear! just call getSurface().setVisible(false)

    There's a bunch of other stuff you can do with PSurface, I've started reading the source code to learn about all the functionalities and it's quite handy -

  • edited April 2016

    This new window doesn't initiate the sketchPath field properly, ...

    We can use the argument "--sketch-path=" + sketchPath() in order to correctly initialize a PApplet's sketchPath: *-:)


    final String[] projectorArgs = {
      "--sketch-path=" + sketchPath(), 
    projector = new Projector(sharedImg); // instantiate
    runSketch(projectorArgs, projector); // ignite
    static class Projector extends PApplet { }
  • Oh cool, I figured there would be a better workaround. Thanks for the info!

Sign In or Register to comment.