| Dynamically set the length of a figure based on the text [message #223149] |
Wed, 20 September 2006 15:40  |
Barry Dresdner 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 #223165 is a reply to message #223157] |
Wed, 20 September 2006 20:29   |
|
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 10:14  |
Barry Dresdner 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.
>>>
>>
>>
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.04061 seconds