Wednesday, November 30, 2011

Re: getOffsetHeight returns 0 although onload has been called

getOffsetHeight/Width only returns a value other than 0 if the element has been successfully rendered by the browser (possibly including elements that have visibility:hidden css).

When you call DeckLayoutPanel.setWidget(w) the DeckLayoutPanel schedules a layout command which will be executed after all of your code has been executed and just before the browser takes back control (see: Scheduler.get().scheduleFinally()). I think this has been done because you could call DeckLayoutPanel.setWidget() multiple times in your code, but when your code is done, the necessary DOM operations will be executed only once.

You can force the DOM operations by calling DeckLayoutPanel.forceLayout() just after you have called DeckLayoutPanel.setWidget() and then try to do your calculations. But I am not quite sure if its enough. If not, your best bet is to defer your calculations until everything has been rendered by the browser:

final Panel p = ...
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
  public void run() {
    p.getOffsetHeight() ... //calculate your stuff
  }
});

Using a deferred command should definitely work.

-- J.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/OdIl5VrlkJMJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment