To draw a gradient background: two colors : CLabel « SWT « Java Tutorial






To draw a gradient background: two colors
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
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 CLabelGradientBackground {
  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("CLabel Gradient");

    shell.setLayout(new GridLayout(1, false));

    // Create the CLabels
    CLabel one = new CLabel(shell, SWT.LEFT);
    one.setText("First Gradient Example");
    one.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    one.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_GRAY));
    // Set the background gradient
    one.setBackground(new Color[] { shell.getDisplay().getSystemColor(SWT.COLOR_RED),
        shell.getDisplay().getSystemColor(SWT.COLOR_GREEN),
        shell.getDisplay().getSystemColor(SWT.COLOR_BLUE) }, new int[] { 50, 50 });

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








17.14.CLabel
17.14.1.The CLabel ClassThe CLabel Class
17.14.2.Label vs. CLabel
17.14.3.Creating a CLabel
17.14.4.CLabel: left and shadow inCLabel: left and shadow in
17.14.5.CLabel: center and shadow outCLabel: center and shadow out
17.14.6.CLabel: right and shadow noneCLabel: right and shadow none
17.14.7.To draw a gradient background: two colorsTo draw a gradient background: two colors
17.14.8.To draw a gradient background: three colorsTo draw a gradient background: three colors
17.14.9.Set the background image of a CLabel objectSet the background image of a CLabel object