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 › How to Resize() window
Page Index Toggle Pages: 1
How to Resize() window? (Read 3205 times)
How to Resize() window?
Apr 27th, 2008, 9:24pm
 
According to a post from a year back, one could resize the Processing main window with a call to

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

But I cannot get any aspect of this to work.  That is, even the simplified code:

void setup() {
 size(200,200);
 
 size(300,300);
 frame.setSize(300,300);
}

fails.  It appears to hang.  Can anyone help with this?

I was planning on creating a mouse-resizeable window, but am not past first base.

Thanks

Bill Wright
Re: How to Resize() window?
Reply #1 - Apr 28th, 2008, 3:11pm
 
you may need to call frame.setResizable(true). also, calling size() and frame.setSize() is redundant (it wasn't a year ago when that original post was created). just pick one.

also, calling size() twice inside setup() is bound to cause trouble.
Re: How to Resize() window?
Reply #2 - Apr 29th, 2008, 2:00am
 
Thanks.  

The combination that works is to call frame.setResizable(true) in setup() and then to use frame.setSize(w,h) in draw().  

It seems to be a nono to leave out the setResizable() because at least background() doesn't work without it.  and calling size() in draw()with different arguments than the intial call in setup() doesn't seem to work at all.  it throws an exception and gets the error message 'new renderer', regardless of calling setResizable(), etc.

Thanks for your help.


Re: How to Resize() window?
Reply #3 - Jun 29th, 2008, 9:13pm
 
I'm trying to use what you speak about. But it doesn't work
My code is:

boolean w=false;
boolean h=false;

void setup(){
 frame.setResizable(true);
}

void draw(){
 if(w){
   frame.setSize(width+10,height);
   println("w="+wi+" and h="+height);
 }if(h){
   frame.setSize(width,height-10);
   println("h="+height+" and w="+height);
 }
 w=false;
 h=false;
}  

void keyPressed(){
 if(key=='w'||key=='W'){
   w=true;
 }
 if(key=='h'||key=='H'){
   h=true;
 }
}

but, when I press h, first time the code print h=100 and w=100
the second time:
h=56 and w=56
wich doesn't make any sens!

Third time the exception:
java.lang.IllegalArgumentException: Width (115) and height (0) cannot be <= 0


Another non working exemple is:

void setup(){
 frame.setResizable(true);
 frameRate(1);
}

void draw(){
frame.setSize(constrain(mouseX*2,20,500),constrain(mouseY*2,20,500));
}

java.lang.IllegalArgumentException: Width (115) and height (0) cannot be <= 0

     at java.awt.image.DirectColorModel.createCompatibleWritableRaster(Unknown Source)

And by the way, once I resize, how can I tell to the html page to resize?
Re: How to Resize() window?
Reply #4 - Jun 30th, 2008, 12:25am
 
I can be wrong, but I believe the above applies to the window produced by the PDE, ie. as desktop application.
AFAIK (ie. somebody might tell otherwise), an applet can't resize itself inside a Web page. At best, you can use a JavaScript function to change the width and height attributes of the object tag loading the Java applet. I suppose you can make something in the applet communicating with the JavaScript in the same page, but it would be much easier to let the page handle all the resizing stuff.
Now, perhaps JS must still communicate the new size to the applet, unless there is a mean to find such change internally.
Re: How to Resize() window?
Reply #5 - Jan 7th, 2009, 11:41pm
 
To handle the 'height(0) cannot be <= 0' message drop this into setup():

Edit: woops, the int had to be placed inside the event handler

frame.addComponentListener(new ComponentAdapter() {
   public void componentResized(ComponentEvent e) {
     int minHeight = 50;//your preferred minimum height
     if(e.getSource()==frame) { if (frame.getHeight() < minHight) frame.setSize(frame.getWidth(), minHeight); }
   }
 } );
Page Index Toggle Pages: 1