`
wufei123
  • 浏览: 1052 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

改变swt中table选中行的颜色

阅读更多
    import org.eclipse.swt.*;  
    import org.eclipse.swt.graphics.*;  
    import org.eclipse.swt.widgets.*;  
      
    public class Example3 {  
      
    public static void main(String[] args) {  
        Display display = new Display();   
        Shell shell = new Shell(display);  
        final Color red = display.getSystemColor(SWT.COLOR_RED);  
        final Color yellow = display.getSystemColor(SWT.COLOR_YELLOW);  
        final Table table = new Table(shell, SWT.FULL_SELECTION);  
        table.setHeaderVisible(true);  
        new TableColumn(table, SWT.NONE).setWidth(100);  
        new TableColumn(table, SWT.NONE).setWidth(100);  
        new TableColumn(table, SWT.NONE).setWidth(100);  
        for (int i = 0; i < 5; i++) {  
            TableItem item = new TableItem(table, SWT.NONE);  
            item.setText(0, "item " + i + " col 0");  
            item.setText(1, "item " + i + " col 1");  
            item.setText(2, "item " + i + " col 2");  
        }  
        table.pack();  
      
        /* 
         * NOTE: EraseItem is called repeatedly.  Therefore it is critical 
         * for performance that this method be as efficient as possible. 
         */  
        table.addListener(SWT.EraseItem, new Listener() {  
            public void handleEvent(Event event) {  
                event.detail &= ~SWT.HOT;  
                if ((event.detail & SWT.SELECTED) == 0) return; /* item not selected */  
                int clientWidth = table.getClientArea().width;  
                GC gc = event.gc;  
                Color oldForeground = gc.getForeground();  
                Color oldBackground = gc.getBackground();  
                gc.setForeground(red);  
                gc.setBackground(yellow);  
                gc.fillGradientRectangle(0, event.y, clientWidth, event.height, false);  
                gc.setForeground(oldForeground);  
                gc.setBackground(oldBackground);  
                event.detail &= ~SWT.SELECTED;  
            }  
        });  
      
        shell.pack();  
        shell.open();  
        while (!shell.isDisposed()) {  
            if (!display.readAndDispatch()) display.sleep();  
        }  
        display.dispose();  
    }  
    }  

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics