We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › problem resizing a window on the fly
Page Index Toggle Pages: 1
problem resizing a window on the fly (Read 475 times)
problem resizing a window on the fly
Aug 1st, 2008, 2:11pm
 
Hi.

I cannot get my processing applet to resize after it has been launched. I can change the frame size with frame.setSize(w,h) but this just resizes the frame and not the sketch.

This is my simple code to test resizing a sketch:

int i;
void setup(){
i=200;
size(i,400);
background(100);
noLoop();
}
void draw(){
background(100);
}

void mousePressed(){
 println("press");
 i=i+50;
 size(i,400);
 frame.setSize(i,400);
 redraw();
}

this throws this exception:
java.lang.RuntimeException: new renderer

at processing.core.PApplet.size(PApplet.java:1032)

at processing.core.PApplet.size(PApplet.java:939)

I have seen:
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Syntax;action=display;num=1191000808

and

http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Integrate;actio n=display;num=1147684168

when running seltar's example in the second link, I get the same problem.

Seltar uses this method:

void resize(int w, int h)
{
 size(w,h);
 frame.setSize(w,h);
}

which again causes the same error.

Thanks for any help,
RR
Re: problem resizing a window on the fly
Reply #1 - Aug 1st, 2008, 6:34pm
 
Mmm, I looked in PApplet code, and I see various ways to do this. Theoretically, it should work but for some reason, we get this exception.
A possible solution is to set g to null before calling size(). A bit extreme, not sure if it has bad size effects.
Another way is to do the steps done in the right size() path:

 setRendererSize(i, 400);
 setSize(i, 400);

But the frame isn't resized. You have to call frame.setSize() but taking in account decorations.

If I paste code from internals of Processing:

       frame.pack();  // get insets. get more.
       Insets insets = frame.getInsets();

       int windowW = Math.max(width, MIN_WINDOW_WIDTH) +
         insets.left + insets.right;
       int windowH = Math.max(height, MIN_WINDOW_HEIGHT) +
         insets.top + insets.bottom;

       frame.setSize(windowW, windowH);

the frame is correctly resized (along with the above code, of course).

My final test code looks like:
Code:
int i = 200;
Insets insets;

void setup() {
size(200, 400);
background(100);
frame.pack(); // get insets. get more.
insets = frame.getInsets();
}
void draw() {
background(100);
line(0, 0, width, height);
line(0, height, width, 0);
}

void mousePressed() {
println("press");
i=i+50;
setRendererSize(i, 400);
setSize(i, 400);

int windowW = Math.max(width, MIN_WINDOW_WIDTH) +
insets.left + insets.right;
int windowH = Math.max(height, MIN_WINDOW_HEIGHT) +
insets.top + insets.bottom;

frame.setSize(windowW, windowH);
}
Re: problem resizing a window on the fly
Reply #2 - Aug 1st, 2008, 7:35pm
 
That works perfectly. Thanks a lot.
Page Index Toggle Pages: 1