I need to get the width of a widget after it has been rendered on the screen, because when I try to get its width after it is attached it returns zero. What is the earliest time I can retrieve the valid offsetwidth of a widget?
Thanks in advance!
The offset width of the box only is known after the browser had built the content of the page. Use scheduleDefferred()
, then you can get the value.
Example:
final TextBox yourInput = new TextBox();
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
int width = yourInput.getOffsetWidth();
/* Do anything with width */
}
});
Take a look at Widget's onLoad() method. It is a no op method you can override, immeditely called after a widget becomes attached to the browser's document.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With