Skip to main content



      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 16:35 Go to next message
Eclipse UserFriend
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 10:25 Go to previous message
Eclipse UserFriend
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 Jul 23 17:13:14 EDT 2025

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

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

Back to the top