改变swt中table选中行的颜色_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > 改变swt中table选中行的颜色

改变swt中table选中行的颜色

 2013/7/19 18:58:11  wufei123  程序员俱乐部  我要评论(0)
  • 摘要:importorg.eclipse.swt.*;importorg.eclipse.swt.graphics.*;importorg.eclipse.swt.widgets.*;publicclassExample3{publicstaticvoidmain(String[]args){Displaydisplay=newDisplay();Shellshell=newShell(display);finalColorred=display.getSystemColor(SWT
  • 标签:SWT
class="java">    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();  
    }  
    }  

?

发表评论
用户名: 匿名