Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT - Browser window resized handler

Tags:

gwt

I am developing a GWT application that render a text on a canvas. I want to resize the canvas whenever browser window resized. The problem is if I used Window.addResizeHandler, the rendering process with each resize will be very slow. So I need a way to resize the canvas only when the user release the mouse button after finishing resize. Is there anyway to do that?

like image 854
HaiderSahib Avatar asked Apr 17 '11 10:04

HaiderSahib


2 Answers

You could add a delay, so that the resize is only processed after the window hasn't been resized for some number of milliseconds:

Window.addResizeHandler(new ResizeHandler() {

  Timer resizeTimer = new Timer() {  
    @Override
    public void run() {
      doComplexLayoutCalculations();
    }
  };

  @Override
  public void onResize(ResizeEvent event) {
    resizeTimer.cancel();
    resizeTimer.schedule(250);
  }
});
like image 184
Riley Lark Avatar answered Nov 17 '22 20:11

Riley Lark


Window.addResizeHandler(new ResizeHandler() {

    @Override
    public void onResize(ResizeEvent event) {
        Scheduler.get().scheduleDeferred(
                new Scheduler.ScheduledCommand() {
                    public void execute() {
                        // layout stuff
                    }
                });
    }

});
like image 3
Ser Yoga Avatar answered Nov 17 '22 20:11

Ser Yoga