SWT/Jface CTabFolder的setSelectionBackground方法

背景色渐变的功能。可以参考以下的代码

 

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值