背景色渐变的功能。可以参考以下的代码
/**
* Specify a gradient of colors to be drawn in the background of the unselected tab.
* For example to draw a vertical gradient that varies from dark blue to blue and then to
* white, use the following call to setBackground:
* <pre>
* cfolder.setBackground(new Color[]{display.getSystemColor(SWT.COLOR_DARK_BLUE),
* display.getSystemColor(SWT.COLOR_BLUE),
* display.getSystemColor(SWT.COLOR_WHITE),
* display.getSystemColor(SWT.COLOR_WHITE)},
* new int[] {25, 50, 100}, true);
* </pre>
*
* @param colors an array of Color that specifies the colors to appear in the gradient
* in order of appearance from top to bottom or left to right. The value
* <code>null</code> clears the background gradient. The value <code>null</code>
* can be used inside the array of Color to specify the background color.
* @param percents an array of integers between 0 and 100 specifying the percent of the width
* of the widget at which the color should change. The size of the <code>percents</code>
* array must be one less than the size of the <code>colors</code> array.
* @param vertical indicate the direction of the gradient. <code>True</code> is vertical and <code>false</code> is horizontal.
*
* @exception SWTException <ul>
* <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
* <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
* </ul>
*
* @since 3.6
*/
public void setBackground(Color[] colors, int[] percents, boolean vertical) {
checkWidget();
if (colors != null) {
if (percents == null || percents.length != colors.length - 1) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
for (int i = 0; i < percents.length; i++) {
if (percents[i] < 0 || percents[i] > 100) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
if (i > 0 && percents[i] < percents[i-1]) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
}
if (getDisplay().getDepth() < 15) {
// Don't use gradients on low color displays
colors = new Color[] {colors[colors.length - 1]};
percents = new int[] {};
}
}
// Are these settings the same as before?
if ((gradientColors != null) && (colors != null) &&
(gradientColors.length == colors.length)) {
boolean same = false;
for (int i = 0; i < gradientColors.length; i++) {
if (gradientColors[i] == null) {
same = colors[i] == null;
} else {
same = gradientColors[i].equals(colors[i]);
}
if (!same) break;
}
if (same) {
for (int i = 0; i < gradientPercents.length; i++) {
same = gradientPercents[i] == percents[i];
if (!same) break;
}
}
if (same && this.gradientVertical == vertical) return;
}
// Store the new settings
if (colors == null) {
gradientColors = null;
gradientPercents = null;
gradientVertical = false;
setBackground((Color)null);
} else {
gradientColors = new Color[colors.length];
for (int i = 0; i < colors.length; ++i) {
gradientColors[i] = colors[i];
}
gradientPercents = new int[percents.length];
for (int i = 0; i < percents.length; ++i) {
gradientPercents[i] = percents[i];
}
gradientVertical = vertical;
setBackground(gradientColors[gradientColors.length-1]);
}
// Refresh with the new settings
redraw();
}