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 & HelpSyntax Questions › Detect window resize event with setResizable
Page Index Toggle Pages: 1
Detect window resize event with setResizable ? (Read 1631 times)
Detect window resize event with setResizable ?
Oct 27th, 2007, 3:00pm
 
I have just discovered the frame.setResizable() method to make the Processing window resizeable. However it seems that if you are not actively looping, it will not automatically redraw (either while dragging or when the mouse is released from dragging).

In the example below, change the window size by dragging the bottom right corner (there is no graphic corner as such). On OSX at least the screen then goes grey and will only redraw once you click.

Is there a way to gain access to the ComponentListener events to call a redraw()?
It would be good to have the option to do this when the mouse is released, and possibly when it is being dragged.

Thanks in advance!

Quote:

void setup(){
 size (320, 240);
 frame.setResizable(true);
 noLoop();
}

void draw(){
 background(255);
 rect(10, 10, 100, 100);
}

public void mousePressed() {
 redraw();
}
Re: Detect window resize event with setResizable ?
Reply #1 - Oct 27th, 2007, 8:56pm
 
hi, for information, I don't have this problem on Windows XP / Processing 0125. the frame redraws itself after being resized. it seems like it's a platform dependent issue (?)

anyway, you can try this to detect resized events :

Code:
frame.addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
if(e.getSource()==frame) {
println("resized");
}
}
});
Re: Detect window resize event with setResizable ?
Reply #2 - Oct 28th, 2007, 1:39am
 
Thanks for that.

However it does appear to be a bug. Adding the code as below does call the redraw some what erratically but once the mouse is released, more often than not (9 times out of 10) the screen is grey.

I have added a bug report here:
http://dev.processing.org/bugs/show_bug.cgi?id=664

Thanks again.

Quote:

void setup(){
 size (320, 240);
 frame.setResizable(true);

 frame.addComponentListener(new ComponentAdapter() {
   public void componentResized(ComponentEvent e) {
     if(e.getSource()==frame) {
       redraw();
     }
   }
 }
 );

 noLoop();
}

void draw(){
 background(255);
 rect(10, 10, 100, 100);
}

public void mousePressed() {
 redraw();
}
Page Index Toggle Pages: 1