How get widget width, after it's drawed ?

170 views
Skip to first unread message

Michał Zakrzewski

unread,
Jan 21, 2013, 8:34:29 AM1/21/13
to google-we...@googlegroups.com
Hi,

I need take VLayout width, but first I must know that it's drawed. How I can check this and get width value after ?

Jens

unread,
Jan 21, 2013, 8:54:07 AM1/21/13
to google-we...@googlegroups.com
The safest thing to do is to use Scheduler.get().scheduleDeferred() inside Widget.onLoad() or Widget.addAttachHandler(). This will schedule a command that is slightly delayed so that the browser has enough time to render everything. Then you can read height/width values.

Widget.isAttached() is also available but it only tells you that the widget is attached to the DOM and not if its correctly rendered yet.

-- J.


Michał Zakrzewski

unread,
Jan 21, 2013, 9:09:31 AM1/21/13
to google-we...@googlegroups.com
I have that code in my app

Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {

@Override
public void execute() {

try {

answerPanelHeight = display.getAnswerPanel().getOffsetHeight();

display.getNextButtonPanel().setHeight(answerPanelHeight);

display.getNextButtonPanel().redraw();

} catch (Exception e) {

}

}
});

What argument I must add in Widget.addAttachHandler() ? Because I use SmartGwt and i dont have method onLoad();

Jens

unread,
Jan 21, 2013, 9:42:37 AM1/21/13
to google-we...@googlegroups.com
panel.addAttachHandler(new AttachEvent.Handler() {
  public void onAttachOrDetach(AttachEvent event) {
    if(event.isAttached()) {
       //scheduler here
    }
  }
});

Widget.onLoad() is protected so you need to override it in sub classes or implement it anonymously.

-- J.

Michał Zakrzewski

unread,
Jan 21, 2013, 10:01:34 AM1/21/13
to google-we...@googlegroups.com
Thanks for your help, but my problem is still not resolved. Sometimes I have good value, sometimes not...

Paul Stockley

unread,
Jan 22, 2013, 1:29:50 PM1/22/13
to google-we...@googlegroups.com
Try this method that uses ComputedStyle. I couldn't be bothered to optimize it with deferred binding so it does some runtime checks.

static public native String getComputedStyleProperty(Element el, String property) /*-{
        if (window['getComputedStyle']) { // W3C DOM method
    if (property === 'float')
    property = 'cssFloat';

            var value = el.style[property], computed;

            if (!value) {
                computed = el['ownerDocument']['defaultView']['getComputedStyle'](el, null);
                if (computed) { // test computed before touching for safari
                    value = computed[property];
                }
            }
            return value;

        } else if (el['currentStyle']) {
            var value;

            switch(property) {
                case 'opacity' :// IE opacity uses filter
                    value = 100;
                    try { // will error if no DXImageTransform
                        value = el.filters['DXImageTransform.Microsoft.Alpha'].opacity;

                    } catch(e) {
                        try { // make sure its in the document
                            value = el.filters('alpha').opacity;
                        } catch(err) {
                        }
                    }
                    return value / 100;
                case 'float': // fix reserved word
                    property = 'styleFloat'; // fall through
                default:
                    value = el['currentStyle'] ? el['currentStyle'][property] : null;
                    return ( el.style[property] || value );
            }
        }
        return "";
}-*/;

Sanjiv Jivan

unread,
Feb 5, 2013, 11:14:32 AM2/5/13
to google-we...@googlegroups.com
Since you're using SmartGWT, use addDrawHandler(..). The callback gets invoked after the widget is rendered.

vLayout.addDrawHandler(new DrawHandler() {
    @Override
    public void onDraw(DrawEvent drawEvent) {
        ..
    }
})


--
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/-/iI4QFhUWRsYJ.

To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Reply all
Reply to author
Forward
0 new messages