[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: Label background

Hi,

True transparency like this is not supported, setBackgroundMode() will only
inheirit a paren't background based on its colour or its background image.
I think the only way to fake it is to draw the parent's content to an image
and set it as the background image, as demonstrated below.  The provided
snippet is very simple though, and the Shell does not have style
SWT.NO_BACKGROUND, so using this approach may or may not be realistic in
your context, depending on how frequently the parent's drawn content
changes.

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setBounds(10,10,200,200);
    shell.setBackgroundMode(SWT.INHERIT_DEFAULT);
    Image image = new Image(display, 200, 200);
    GC gc = new GC(image);
    gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
    gc.fillRectangle(0, 0, 200, 200);
    gc.drawLine(0, 0, 200, 200);
    gc.drawLine(0, 200, 200, 0);
    gc.dispose();
    shell.setBackgroundImage(image);
    Label label = new Label(shell, SWT.BORDER);
    label.setText("abcd efghi jklm nop");
    label.setBounds(50,100,100,50);
    shell.open();
    while (!shell.isDisposed()){
        if (!display.readAndDispatch()) display.sleep();
    }
    image.dispose();
    display.dispose();
}

HTH,
Grant


"dnise" <dnise@xxxxxxxxxxx> wrote in message
news:fti6ra$asj$1@xxxxxxxxxxxxxxxxxxxx
> Hi everyone:
> I wanna to set the transparent background for label,Because I have set
> No_BackGround for composite.  I have already used setBackgroundMode(),But
> it doesn't work. can any one tell me how to complete this?
> Dnise
> 2008-04-9