Can Sketch Window be Resized?

All the Processing sketch windows I've made are fixed size. Maximise and size options are greyed out. (Using Windows a the moment. Size() without P2D or P3D.) Is it possible to make a resizable window? Is there a resize event function? (I've looked at doc on Size and Environment, not seen anything there.)

Answers

  • Answer ✓
    void setup(){
      size(400,400);
      //frame.setResizable(true); // Pre-Processing V3.
      surface.setResizable(true);
      fill(255);
    }
    
    void draw(){
      background(0);
      ellipse(width-40,height-40,20,20);
    }
    
  • edited December 2016

    //frame.setResizable(true); // Pre-Processing V3.

    Actually frame.setResizable(true); still works for P3, even though it's deprecated. ;;)

  • Does that always work on P3, even if the renderer uses JavaFX?

  • edited December 2016 Answer ✓

    Java doesn't have the a resize event but you can simulate your own

    int w, h;
    
    void setup () {
      size(400, 400);
      w=width;
      h=height ;
      registerMethod ("pre", this ) ;
    } 
    
    void pre () {
      if (w != width || h != height) {
        w=width ;
        h=height ;
        // window size change 
      } 
    } 
    

    The pre method is called just before the draw method

  • @GoToLoop It doesn't work for me if I use P2D, P3D or FX2D.

  • Thanks all. Working for me (without P2D or P3D).

Sign In or Register to comment.