Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » getGC
getGC [message #437951] Mon, 14 June 2004 12:08 Go to next message
Tobias Weih is currently offline Tobias WeihFriend
Messages: 8
Registered: July 2009
Junior Member
hi,

I am trying to calculate the width of a String by doing s.th. like:

public int getStringWidth(String str)
{
gc.setFont(f);
Point extent = gc.stringExtent(str);
return extent.x;
}

problem is: where do I get the GC-reference??

thanks tobi
Re: getGC [message #437961 is a reply to message #437951] Mon, 14 June 2004 13:08 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Typically you create and dispose one on the Drawable that the text is to be
rendered on, where Drawable is a Control, Device or Image. See GC's
constructor. The only time you wouldn't do this is if a gc is provided to
you (eg.- in a paint callback).

Grant

"Tobias Weih" <tobias.weih@oseg.org> wrote in message
news:cak4gj$sc$1@eclipse.org...
> hi,
>
> I am trying to calculate the width of a String by doing s.th. like:
>
> public int getStringWidth(String str)
> {
> gc.setFont(f);
> Point extent = gc.stringExtent(str);
> return extent.x;
> }
>
> problem is: where do I get the GC-reference??
>
> thanks tobi
>
Re: getGC [message #437963 is a reply to message #437951] Mon, 14 June 2004 13:02 Go to previous messageGo to next message
Tobias Weih is currently offline Tobias WeihFriend
Messages: 8
Registered: July 2009
Junior Member
sorry, got it.

I am instanciating a new GC.
Re: getGC [message #437967 is a reply to message #437963] Mon, 14 June 2004 13:48 Go to previous message
Eclipse UserFriend
Originally posted by: richkulp.NO.SPAM.us.ibm.com

If it is a new one you created just for this usage, don't forget to
dispose it when done.

--
Thanks, Rich Kulp

Previous Topic:Multiline Text in a List
Next Topic:Can I disable a section in the StyledText (customized editor)
Goto Forum:
  


Current Time: Sat Apr 27 17:30:41 GMT 2024

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

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

Back to the top