Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Dynamically set the length of a figure based on the text
Dynamically set the length of a figure based on the text [message #223149] Wed, 20 September 2006 19:40 Go to next message
Barry Dresdner is currently offline Barry DresdnerFriend
Messages: 75
Registered: July 2009
Member
I'd like to set the length of a figure based on the text it contains. I
don't always know what the text will be, nor do I know the Font name, style
or size. With AWT, I was able to use the FontMetrics class and call the
stringWidth method passing in the text. This would return an integer value
representing the width of the text in pixels. Is there something similar I
can use within the GEF framework? It is for a compontent within a graph.
Thanks in advance.
Re: Dynamically set the length of a figure based on the text [message #223157 is a reply to message #223149] Wed, 20 September 2006 20:31 Go to previous messageGo to next message
Barry Dresdner is currently offline Barry DresdnerFriend
Messages: 75
Registered: July 2009
Member
After researching this a bit further, it looks like I can probably use
GC.textExtent as follows:

Display display = Display.getCurrent();
GC gc = new GC(display);
Point pt = gc.textExtent(myText);
this.setSize(new Dimension(pt));

However I'm not sure about using Display.getCurrent() to instantiate GC.
Can anyone tell me if this is correct? My main concern is that GC is
computing the size based on the font used by GEF.
Thanks - barry


"Barry Dresdner" <barry.dresdner@softwareagusa.com> wrote in message
news:ees5g8$t96$1@utils.eclipse.org...
> I'd like to set the length of a figure based on the text it contains. I
> don't always know what the text will be, nor do I know the Font name,
> style or size. With AWT, I was able to use the FontMetrics class and call
> the stringWidth method passing in the text. This would return an integer
> value representing the width of the text in pixels. Is there something
> similar I can use within the GEF framework? It is for a compontent within
> a graph. Thanks in advance.
>
Re: Dynamically set the length of a figure based on the text [message #223165 is a reply to message #223157] Thu, 21 September 2006 00:29 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.unknown.com

Use FigureUtilties#getTextExtents().

"Barry Dresdner" <barry.dresdner@softwareagusa.com> wrote in message
news:ees8ed$eia$1@utils.eclipse.org...
> After researching this a bit further, it looks like I can probably use
> GC.textExtent as follows:
>
> Display display = Display.getCurrent();
> GC gc = new GC(display);
> Point pt = gc.textExtent(myText);
> this.setSize(new Dimension(pt));
>
> However I'm not sure about using Display.getCurrent() to instantiate GC.
> Can anyone tell me if this is correct? My main concern is that GC is
> computing the size based on the font used by GEF.
> Thanks - barry
>
>
> "Barry Dresdner" <barry.dresdner@softwareagusa.com> wrote in message
> news:ees5g8$t96$1@utils.eclipse.org...
>> I'd like to set the length of a figure based on the text it contains. I
>> don't always know what the text will be, nor do I know the Font name,
>> style or size. With AWT, I was able to use the FontMetrics class and
>> call the stringWidth method passing in the text. This would return an
>> integer value representing the width of the text in pixels. Is there
>> something similar I can use within the GEF framework? It is for a
>> compontent within a graph. Thanks in advance.
>>
>
>
Re: Dynamically set the length of a figure based on the text [message #223235 is a reply to message #223165] Thu, 21 September 2006 14:14 Go to previous message
Barry Dresdner is currently offline Barry DresdnerFriend
Messages: 75
Registered: July 2009
Member
Thank you. That is exactly what I was looking for.

"Pratik Shah" <none@unknown.com> wrote in message
news:eesmdh$7gr$1@utils.eclipse.org...
> Use FigureUtilties#getTextExtents().
>
> "Barry Dresdner" <barry.dresdner@softwareagusa.com> wrote in message
> news:ees8ed$eia$1@utils.eclipse.org...
>> After researching this a bit further, it looks like I can probably use
>> GC.textExtent as follows:
>>
>> Display display = Display.getCurrent();
>> GC gc = new GC(display);
>> Point pt = gc.textExtent(myText);
>> this.setSize(new Dimension(pt));
>>
>> However I'm not sure about using Display.getCurrent() to instantiate GC.
>> Can anyone tell me if this is correct? My main concern is that GC is
>> computing the size based on the font used by GEF.
>> Thanks - barry
>>
>>
>> "Barry Dresdner" <barry.dresdner@softwareagusa.com> wrote in message
>> news:ees5g8$t96$1@utils.eclipse.org...
>>> I'd like to set the length of a figure based on the text it contains. I
>>> don't always know what the text will be, nor do I know the Font name,
>>> style or size. With AWT, I was able to use the FontMetrics class and
>>> call the stringWidth method passing in the text. This would return an
>>> integer value representing the width of the text in pixels. Is there
>>> something similar I can use within the GEF framework? It is for a
>>> compontent within a graph. Thanks in advance.
>>>
>>
>>
>
>
Previous Topic:IFigure and Graphics
Next Topic:[announce] GEF 3.2.1 Maintenance Release Build available
Goto Forum:
  


Current Time: Tue Mar 19 03:03:58 GMT 2024

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

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

Back to the top