How to find out the width/height of a Label in draw2d [message #25605] |
Tue, 08 October 2002 10:58  |
Eclipse User |
|
|
|
Originally posted by: sy_cheung2.yahoo.com
Could you please tell me how can I find out what is the width (in pixel) and
height of a
certain Label with certain text?
For example, what is the width/height of draw2d Label with "Hello World"?
Some one from (eclipse.tool newsgroup) suggest to use this:
GC gc = new GC(control);
Point extent = gc.stringExtent("Hello");
gc.dispose();
But the GC object takes a Drawable in its constructor, and draw2d label is
not a Drawable object.
Also, it will require me to create a GC object everytime, I would like an
more efficient way.
Thanks for any ideas.
Sam
|
|
|
|
|
Re: How to find out the width/height of a Label in draw2d [message #26577 is a reply to message #26105] |
Wed, 09 October 2002 11:12  |
Eclipse User |
|
|
|
The javadoc for GC.setFont(Font) says, "If the argument is null, then a default
font appropriate for the platform will be used instead."
Eric
"Randy Hudson" <hudsonr@us.eye-bee-em.com> wrote in message
news:ao1cbh$q5l$1@rogue.oti.com...
> > You can get the size (as a Dimension) of some text by using Draw2d's
> > FigureUtilities.getTextExtents(String, Font). You can use null for the
> font and
>
> Is this true? I think there is no default font because default font is
> different for each SWT Control.
>
> > the default font for the system will be used. This class create a new GC,
> but
> > caches it so that you can make multiple calls without any extra overhead.
> Look
> > at Label.getPreferredSize(...) to see how Label calculates its size given
> the
> > text inside of it.
> >
> > Eric
> >
> >
> > "Sam Cheung" <sy_cheung2@yahoo.com> wrote in message
> > news:anuqdq$8qa$1@rogue.oti.com...
> > > Could you please tell me how can I find out what is the width (in pixel)
> and
> > > height of a
> > > certain Label with certain text?
> > > For example, what is the width/height of draw2d Label with "Hello
> World"?
> > >
> > > Some one from (eclipse.tool newsgroup) suggest to use this:
> > > GC gc = new GC(control);
> > > Point extent = gc.stringExtent("Hello");
> > > gc.dispose();
> > >
> > > But the GC object takes a Drawable in its constructor, and draw2d label
> is
> > > not a Drawable object.
> > > Also, it will require me to create a GC object everytime, I would like
> an
> > > more efficient way.
> > >
> > > Thanks for any ideas.
> > > Sam
> > >
> > >
> >
> >
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.39893 seconds