如何将控件设置为透明背景 [英] How to set a control to a transparent background
本文介绍了如何将控件设置为透明背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将控件的背景设置为透明?
我说的是 Label
和文本
控件,但可以是我在GUI中看到的任何标准控件。
解决方案
shell.setBackgroundMode(SWT.INHERIT_FORCE);
会做您想要的事情。
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);
新Label(shell,SWT.NONE).setText( Label);
shell.pack();
shell.open();
而(!shell.isDisposed())
{
if(!display.readAndDispatch())
{
display.sleep();
}
}
display.dispose();
}
看起来像这样:
How do I set the background of a control to be transparent?
I am speaking of Label
and Text
controls at the moment, but can be any of the standard controls that I see in the GUI.
解决方案
shell.setBackgroundMode(SWT.INHERIT_FORCE);
will do what you want.
The
Composite
constant to indicate that an attribute (such as background) is inherited by all children.
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();
}
Looks like this:
这篇关于如何将控件设置为透明背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文