2012-11-29 56 views
3

我目前正在開發一個Eclipse RCP應用程序,該應用程序顯示包含可編輯單元格的多個TableViewer。這些單元通過EMF數據綁定連接到我的模型。JFace TableViewer:使單元格背景色閃爍

現在我想讓單元格編輯後閃爍綠色,意思是將背景顏色設置爲綠色,然後淡出。爲了讓入門更輕鬆,我希望將cell-background-color設置爲綠色,然後在1秒後回到白色。

原因的作用是將背景顏色設置爲綠色,但自從我編輯的ViewerCell自動設置爲null之後,我無法在一秒鐘後將其設置爲白色,並且I不知道爲什麼。

這裏從我CellLabelProvider是一個代碼提取物(即不工作):

@Override 
public void update(final ViewerCell cell) { 
    //this works: 
    cell.setBackground(new Color(Display.getCurrent(), 0, 255, 0));   
    Display.getCurrent().timerExec(1000, new Runnable() { 
      public void run() { 
       //for this I get a NullPointerException: 
       cell.setBackground(new Color(Display.getCurrent(), 255, 255, 255)); 
      } 
    }); 
} 

任何幫助,將不勝感激!

回答

8

有與設置ViewerRow爲NULL ViewerCell https://bugs.eclipse.org/bugs/show_bug.cgi?id=201280

爲了解決這個問題,你有這個問題的補丁相關的錯誤,你不應該使用ViewerCell

試試這個代碼

col.setLabelProvider(new ColumnLabelProvider() { 
      @Override 
      public void update(final ViewerCell cell) { 
       cell.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_DARK_GREEN)); 
       final int index = cell.getColumnIndex(); 
       final TableItem item = (TableItem) cell.getItem(); 
       Display.getCurrent().timerExec(1000, new Runnable() { 
        public void run() { 
         //make sure table is not disposed 
         item.setBackground(index, Display.getDefault().getSystemColor(SWT.COLOR_WHITE)); 
        } 
       }); 
      } 
     }); 
+0

先生,你是我心目中的英雄。整整兩天,我坐在電腦前解決這個問題。它的工作原理與您發佈時完全相同。謝謝! :D – Springsteen

+0

我很高興它解決了你的問題:) –

+0

+1非常好的解決方案。 – Baz