带列的SWT树:在Linux / Mac上,删除行的交替背景色

问题描述

|| 我正在用列(看起来像表)为树的某些列着色。在Windows系统上看起来不错,但在Linux / Mac上却不是,因为它们使用交替的背景色(白色,蓝色,白色,蓝色等)。 我想删除树的交替背景色。有什么想法吗?我试图在这些系统上禁止“ 0”,但它也不会画出我需要的垂直线。     

解决方法

我认为您可以使用所有者抽奖来做到这一点。使用此代码段作为起点,并与此交换
EraseItem
事件处理程序:
public void handleEvent( Event event ) {
   event.detail &= ~SWT.HOT;
   GC gc = event.gc;
   Rectangle area = table.getClientArea();
   /*
    * If you wish to paint the selection beyond the end of
    * last column,you must change the clipping region.
    */
   int columnCount = table.getColumnCount();
   if ( event.index == columnCount - 1 || columnCount == 0 ) {
      int width = area.x + area.width - event.x;
      if ( width > 0 ) {
         Region region = new Region();
         gc.getClipping(region);
         region.add(event.x,event.y,width,event.height);
         gc.setClipping(region);
         region.dispose();
      }
   }
   gc.setAdvanced(true);
   if ( gc.getAdvanced() ) gc.setAlpha(127);
   Rectangle rect = event.getBounds();
   Color background = gc.getBackground();
   gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
   gc.fillRectangle(0,rect.y,500,rect.height);
   // restore colors for subsequent drawing
   gc.setBackground(background);
}
应该可以在GTK(SWT使用的Linux窗口管理器)上工作,并且使用
Trees
,尽管没有尝试过。 由于所有者抽取的成本很高,因此我强烈建议为GTK添加这样的事件处理程序:
if(SWT.getPlatform().equals(\"gtk\")){ ... }
但是SWT的全部要点是具有本机绘图。因为用户感觉“在家”,所以这提高了用户对软件的接受度。也许您可以设计一种方法,而不必为GTK用户删除替代背景。