On 5 oct, 12:59, Rick <[email protected]> wrote:
> Hi all
>
> I am making an application using GWT 1.7. But I am surprised by the
> behaviour I got. I took a vertical panel and add a button on this. I
> set width of button to 500px. Now What I was expected that in onAttach
> () of Vertical panel, before calling super.onAttach(), the offsetWidth
> of vertical panel should be zero. But it is giving me 500px.
>
> VerticalPanel vp = new VerticalPanel() {
> @Override
> protected void onAttach() {
>                 GWT.log("Before super.onAttach called Offset width: " +
> getOffsetWidth(), null);
>                 super.onAttach();
>                 GWT.log(After super.onAttach called Offset width: " + 
> getOffsetWidth
> (), null);
>         }};
>
> Button b = new Button("Hello");
> b.setWidth("500px");
> vp.add(b);
> GWT.log("Before vp attached to RootPanel Offset width: " +
> vp.getOffsetWidth(), null);
> RootPanel.get().add(vp);
>
> Actual output
>         Before vp attached to RootPanel Offset width:0
>         Before super.onAttach called Offset width:500
>         After super.onAttach called Offset width:500
> Expected output
>         Before vp attached to RootPanel Offset width:0
>         Before super.onAttach called Offset width:500
>         After super.onAttach called Offset width:500
>
> Thanks and regards

onAttach() is called after the element (getElement()) has been
attached to the document and the parent widget (getParent()) has been
set (see AbsolutePanel#add(Widget), ComplexPanel#add(Widget,Element),
Panel#adopt(Widget) and Widget#setParent(Widget)).
What super.onAttach() does (Widget#onAttach()) is only sink events,
recursively call onAttach on child widgets, and then call onLoad()
(hence the advice on the JavaDoc about using onLoad to react when the
widget is "fully attached").
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to