I am writing a graphical application using SWT. Firstly I created a shell with image background (shell.setBackgroundImage(image)) then I put a composite with another background image, so that I could use it(composite) to place labels inside it. The problem is that I cannot get rid of the gray border around composite. Is it possible to do at all or perhaps there are others way to do that?
Here is the code:
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class Test {
protected static int gap = 20;
public static void main (String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
Image bg_Image = new Image(display, "bg_full.png");
shell.setBackgroundImage(bg_Image);
shell.setBackgroundMode(SWT.INHERIT_FORCE);
shell.setFullScreen(true);
Image bg = new Image(display, "bg.png");
Image border = new Image(display, "bg_info.png");
Image b1 = new Image(display, "button_total_active.png");
Image b2 = new Image(display, "button_terminal.png");
Image b3 = new Image(display, "button_operator.png");
Image b4 = new Image(display, "button_contract.png");
Composite composite = new Composite(shell, SWT.NONE);
composite.setBackgroundImage(bg);
composite.setBackgroundMode(SWT.INHERIT_FORCE);
composite.setBounds(80, 220, bg.getBounds().width, bg.getBounds().height);
Label label1 = new Label(composite, SWT.NONE);
label1.setImage(b1);
label1.setBounds(gap, gap, b1.getBounds().width, b1.getBounds().height);
Label label2 = new Label(composite, SWT.NONE);
label2.setImage(b2);
label2.setBounds(gap, gap*2+b1.getBounds().height, b2.getBounds().width, b2.getBounds().height);
Label label3 = new Label(composite, SWT.NONE);
label3.setImage(b3);
label3.setBounds(gap, gap*3+b1.getBounds().height*2, b3.getBounds().width, b3.getBounds().height);
Label label4 = new Label(composite, SWT.NONE);
label4.setImage(b4);
label4.setBounds(gap, gap*4+b1.getBounds().height*3, b4.getBounds().width, b4.getBounds().height);
Label label5 = new Label(composite, SWT.NONE);
label5.setImage(border);
label5.setBounds(gap*2+b1.getBounds().width, gap, border.getBounds().width, border.getBounds().height);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
Here is a sample image
These are not gray borders (you removed them by SWT.INHERIT_FORCE), these are transparent corners of the image that are not transparent because there is a composite behind them. As far as I know you cannot remove the corners of the image using it as a background of a Composite. If these corners are transparent (and not white), you can draw this image on the Shell (without creating any Composite) using GC as shown here.
When placing transparent images, put them on the object you expect to see behind. Hope I helped u. 🙂