Unless you set the label to display:block it will expand to the width of its
container (it is actually a div). With display:block it will just be as wide
as it needs.
Why can't you move it once it is added?

Ian

http://examples.roughian.com


2009/8/17 Mike Jacobs <[email protected]>

>
> Once I added the label to the intended container (the map pane in the
> Google map API), the width was calculated correctly.  Since I cannot
> move the widget once it has been added, I add it to get the dimensions
> and then remove it before adding it where it belongs.
>
> Thanks for the help.
>
> Mike
>
> On Aug 17, 7:27 am, Mike Jacobs <[email protected]>
> wrote:
> > The label offset width is zero prior to adding to the root panel and
> > unusually large after adding it.  The width is supposedly 761 for a
> > string of "~~testing~~".  I will experiment with this a bit more but
> > this width seems like it might be the width of the root panel at the
> > time.
> >
> > On Aug 16, 7:15 pm, Ian Bambury <[email protected]> wrote:
> >
> > >         Label label = new Label("Some Text)");
> > >         RootPanel.get().add(label);
> > >         int length = label.getOffsetWidth();
> >
> > > Ian
> >
> > >http://examples.roughian.com
> >
> > > 2009/8/16 Mike Jacobs <[email protected]>
> >
> > > > There is no method to get the width on the Label widget or any of the
> > > > super classes.  How would I get the width?
> >
> > > > On Aug 16, 5:19 pm, Ian Bambury <[email protected]> wrote:
> > > > > Just add it, get the width and then place it where you want it.
> > > > > Ian
> >
> > > > >http://examples.roughian.com
> >
> > > > > 2009/8/16 Mike Jacobs <[email protected]>
> >
> > > > > > I have a case where I am dynamically adding a Label widget with
> > > > > > program determined label text.  (It is adding a Label on top of a
> > > > > > Google Map but this question is about GWT widgets).  Since the
> label
> > > > > > text can vary at run time and I would like to center the label at
> a
> > > > > > specific pixel location, I need to figure out the pixel size of
> the
> > > > > > label to position it properly.
> >
> > > > > > I can specify a pixel width and height when creating the Label.
>  Is it
> > > > > > possible to determine the appropriate size of the Label based on
> the
> > > > > > label text length?  Is is possible to ask the label for it's
> pixel
> > > > > > size afterward instead?
> >
> > > > > > I have been using a simple approach of using width = text length
> * 11
> > > > > > (since the font is 11px) but that appears to be off by a few
> pixels
> > > > > > presumably due to varying width of characters.
> >
> > > > > > Thanks,
> > > > > > Mike
> >
>

--~--~---------~--~----~------------~-------~--~----~
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