How to set a control on a transparent background

How do I set the background transparency of a control?

Now I'm talking about Label and Text controls, but these can be any standard controls that I see in the GUI.

+7
source share
4 answers
 shell.setBackgroundMode(SWT.INHERIT_FORCE); 

will do what you want.

The Composite constant indicates that an attribute (such as a background) is inherited for all child objects.

 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(); } 

It looks like:

enter image description here

+10
source

According to my information, you cannot set the control (with the exception of the shell on some operating systems), transparent or translucent in SWT, for example. show the panel in front of the table control where the table will be displayed through the panel. As other posters wrote, you can only inherit the background.

+2
source

If you add a Composite and specify the following flags, it will be transparent: new Composite(shell, SWT.TRANSPARENT | SWT.NO_BACKGROUND);

+1
source

You need to make the next call for your composite element in front of the child controls, for example, shortcuts inherit the background from the composite.

 composite.setBackgroundMode( SWT.INHERIT_DEFAULT ); 
0
source

All Articles