Mega Code Archive

 
Categories / Java Tutorial / SWT
 

Displaying a Gradient Background

You can configure the selected tab to display a gradient background using CTabFolder's setSelectionBackground() method. import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.custom.CTabItem; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class CTabFolderGradientBackground {   public static void main(String[] args) {     Display display = new Display();     Shell shell = new Shell(display);     shell.setText("Show CTabFolder");     shell.setLayout(new GridLayout(1, true));     CTabFolder tabFolder = new CTabFolder(shell, SWT.TOP);     tabFolder.setBorderVisible(true);     tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));     // Set up a gradient background for the selected tab     tabFolder.setSelectionBackground(new Color[] {         display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW),         display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW),         display.getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW) }, new int[] { 50, 100 });     new CTabItem(tabFolder, SWT.NONE, 0).setText("Tab index 1 ");     shell.open();     while (!shell.isDisposed()) {       if (!display.readAndDispatch()) {         display.sleep();       }     }     display.dispose();   } }