Skip to main content



      Home
Home » Eclipse Projects » GEF » How to find out the width/height of a Label in draw2d
How to find out the width/height of a Label in draw2d [message #25605] Tue, 08 October 2002 10:58 Go to next message
Eclipse UserFriend
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 #25749 is a reply to message #25605] Tue, 08 October 2002 11:51 Go to previous messageGo to next message
Eclipse UserFriend
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
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
>
>
Re: How to find out the width/height of a Label in draw2d [message #26105 is a reply to message #25749] Wed, 09 October 2002 10:16 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: hudsonr.us.eye-bee-em.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
> >
> >
>
>
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 Go to previous message
Eclipse UserFriend
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
> > >
> > >
> >
> >
>
>
Previous Topic:Mixing 2d drawing and UI widgets
Next Topic:Moving figures using GEF drag and drop (minimal example)
Goto Forum:
  


Current Time: Fri May 09 14:06:30 EDT 2025

Powered by FUDForum. Page generated in 0.04736 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top