Displaying a Gradient Background : CTabFolder « SWT « Java Tutorial






You can configure the selected tab to display a gradient background using CTabFolder's setSelectionBackground() method.

Displaying a Gradient Background
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();
  }
}








17.68.CTabFolder
17.68.1.TabFolder/TabItem vs. CTabFolder/CTabItem
17.68.2.Creating a CTabFolder
17.68.3.Add CTabItem to CTabFolderAdd CTabItem to CTabFolder
17.68.4.Add Image to CTabFolderAdd Image to CTabFolder
17.68.5.Set CTabFolder Minimize and Maximize VisibleSet CTabFolder Minimize and Maximize Visible
17.68.6.Add CTabFolder2Adapter to CTabFolderAdd CTabFolder2Adapter to CTabFolder
17.68.7.Displaying a Gradient BackgroundDisplaying a Gradient Background
17.68.8.Add CTabFolder2ListenerAdd CTabFolder2Listener