Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Center text on a Label with a background Image
Center text on a Label with a background Image [message #768817] Tue, 20 December 2011 21:35 Go to next message
drew frantz is currently offline drew frantzFriend
Messages: 340
Registered: July 2009
Senior Member
I am trying to center text on a label that contains a backgroundImage

Label l = new Label(container, SWT.CENTER) ;// also tried
SWT.CENTER|SWT.VERTICAL
l.setBackgroundImage("foo.png");
l.setText("My Text ");
l.setFont(myFont);

seems simple enough, but the text is floating toward the top of the Control
and is not centered vertically. What should I adjust to make sure the text
is centered both horizontally and vertically?
Re: Center text on a Label with a background Image [message #769214 is a reply to message #768817] Wed, 21 December 2011 15:25 Go to previous message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2151
Registered: July 2009
Senior Member
The behaviour you're matches what is natively "correct". This has been
logged a couple of times before, the most recent being
https://bugs.eclipse.org/bugs/show_bug.cgi?id=69394 , and in both cases
the resolution was WONTFIX.

That being said, it's still not difficult to get the effect you want.
You can either use the approach that's described in the last comment of
bug 69394, or you can create a Canvas instead of a Label and paint its
content (
http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet275.java
demonstrates this).

Grant


On 12/20/2011 4:35 PM, Drew wrote:
> I am trying to center text on a label that contains a backgroundImage
>
> Label l = new Label(container, SWT.CENTER) ;// also tried
> SWT.CENTER|SWT.VERTICAL
> l.setBackgroundImage("foo.png");
> l.setText("My Text ");
> l.setFont(myFont);
>
> seems simple enough, but the text is floating toward the top of the
> Control and is not centered vertically. What should I adjust to make
> sure the text is centered both horizontally and vertically?
>
>
>
Previous Topic:Hide popup menu
Next Topic:Porter-Duff composition support?
Goto Forum:
  


Current Time: Wed Nov 26 16:17:33 GMT 2014

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

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