如何将控件设置为透明背景

Sar*_*ger 8 java swt controls transparent

如何将控件的背景设置为透明?

我现在正在谈论LabelText控制,但可以是我在GUI中看到的任何标准控件.

更新:如所选答案所述,我只需在设置背景图像后添加一行(在我的情况下):

__PRE__

完整的代码片段非常有助于解决问题.

Baz*_*Baz 10

shell.setBackgroundMode(SWT.INHERIT_FORCE);
Run Code Online (Sandbox Code Playgroud)

会做你想做的.

Composite用于指示所有子项继承属性(如背景)的常量.

public static void main(String[] args)
{
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new GridLayout(1, false));
    shell.setText("StackOverflow");

    shell.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
    shell.setBackgroundMode(SWT.INHERIT_FORCE);

    new Button(shell, SWT.PUSH).setText("Button");
    new Label(shell, SWT.NONE).setText("Label");

    shell.pack();
    shell.open();

    while (!shell.isDisposed())
    {
        if (!display.readAndDispatch())
        {
            display.sleep();
        }
    }

    display.dispose();
}
Run Code Online (Sandbox Code Playgroud)

看起来像这样:

在此输入图像描述