Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsDynamically set the length of a figure based on the text
https://www.eclipse.org/forums/index.php/mv/msg/71399/223149/#msg_223149
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.]]>Barry Dresdner2006-09-20T19:40:59-00:00Re: Dynamically set the length of a figure based on the text
https://www.eclipse.org/forums/index.php/mv/msg/71399/223157/#msg_223157
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.
>]]>Barry Dresdner2006-09-20T20:31:04-00:00Re: Dynamically set the length of a figure based on the text
https://www.eclipse.org/forums/index.php/mv/msg/71399/223165/#msg_223165
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.
>>
>
>]]>2006-09-21T00:29:34-00:00Re: Dynamically set the length of a figure based on the text
https://www.eclipse.org/forums/index.php/mv/msg/71399/223235/#msg_223235
"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.
>>>
>>
>>
>
>]]>Barry Dresdner2006-09-21T14:14:12-00:00