Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent Background in Java SWT Label

Tags:

java

Is there anyway in Java SWT that I can place a label on top of another label and then have the label on top to have a transparent background?

I am doing this in a class that extends Composite as I want to create a custom SWT "fancy button" out of 2 labels. So the label below will be the lable that consist of only an image while the one on top will be the label with the text of the "fancy button". But the label on top has to have a transparent background so as to not cover the image below it.

Currently, the label on top is covering the label below.

Any idea how I could do this?

Thanks!

like image 928
Carven Avatar asked Nov 05 '22 22:11

Carven


1 Answers

Instead you could try doing the following to get the same result.

  • Create a label
  • Assign an image to the label using a shell
  • Then use "setText()" to write something on the label.

The Text will appear above the image. You will be able to see the image.

( Showing only relavent code ) Example of Label with text/image.

 Image image = new Image(display, "c:\\picture.jpeg"); 
 Shell shell = new Shell(SWT.NO_TRIM);
 shell.setBounds(10,10,200,200);
 shell.setBackgroundImage(image);
 shell.setBackgroundMode(SWT.INHERIT_DEFAULT);
 Label label = new Label(shell, SWT.NONE);
 label.setText("LAbel text here. ");

Since you want to make buttons. You can use the same logic, using the "Button" api as well. You can create a button with an image and then set any text above it.

( Showing only relavent code ) Example of Button

Button button = new Button(shell, SWT.PUSH);
button.setImage(image);
button.setText("Click Me");

I hope this is what you are trying to do.

like image 55
kensen john Avatar answered Nov 15 '22 11:11

kensen john