private void makeHeadColumns(Table table, DBDataHeadModel[] dhs) {
table.clearAll();
TableColumn[] cols = table.getColumns();
int length = dhs.length;
for (int i = 0; i < cols.length; i++) {
TableColumn tc = cols[i];
tc.dispose();
}
for (int i = 0; i < length; i++) {
TableColumn tc = new TableColumn(table, SWT.LEFT);
DBDataHeadModel dh = dhs[i];
tc.setText(dh.getLabel());
tc.setAlignment(getAlighment(dh.getType()));
int size = dh.getDisplaySize() * 12;
if (size > 500) {
size = 500;
}
tc.setWidth(size);
}
}

解决方案 »

  1.   

    处理SWT控件的paint事件,我花了几个礼拜写了个类似Excel的SWT控件,有想写控件的朋友可以想我要,[email protected] QQ56299927
    protected void onPaint()
    {
    CellRange rowrange,colrange;
    m_imgDoubleDrawBuffer = new Image(null,getClientArea());
    GC memgc = new GC(m_imgDoubleDrawBuffer);
    drawClientArea(memgc);
    GC gc=new GC(this); //TopLeftCell
    for(int col=0;col<getFixedColCount();col++)
    {
    for(int row=0;row<getFixedRowCount();row++)
    {
    drawFixedCell(memgc,row,col);
    }
    } rowrange = getFixedRowVisibleCellRange();
    //FixedRowCell
    for(int col=rowrange.left;col<=rowrange.right;col++)
    {
    for(int row=0;row<getFixedRowCount();row++)
    {
    drawFixedCell(memgc,row,col);
    }
    }
    colrange = getFixedColVisibleCellRange();
    //FixedColCell
    for(int row=colrange.top;row<=colrange.bottom;row++)
    {
    for(int col=0;col<getFixedColCount();col++)
    {
    drawFixedCell(memgc,row,col);
    }
    }
    //NoneFixedCell
    for(int col=rowrange.left;col<=rowrange.right;col++)
    {
    for(int row=colrange.top;row<=colrange.bottom;row++)
    {
    if(getCell(row,col).isCellFocused())
    {

    drawNoneFixedCell(memgc,row,col);
    memgc.setBackground(new Color(null,0,0,130));
    memgc.fillRectangle(getCellRect(row,col).x+1,getCellRect(row,col).y+1
    ,getCellRect(row,col).width-1,getCellRect(row,col).height-1);
    memgc.setForeground(new Color(null,255,255,255));
    memgc.drawString(getCellText(row,col),getCellTopLeft(row,col).x,getCellTopLeft(row,col).y,true);
    }
    else
    drawNoneFixedCell(memgc,row,col);

    }
    }
    gc.drawImage(m_imgDoubleDrawBuffer,0,0);
    if(gc!=null)
    {
    gc.dispose();
    gc=null;
    }
    if(memgc!=null)
    {
    memgc.dispose();
    memgc=null;
    }
    if(m_imgDoubleDrawBuffer!=null)
    {
    m_imgDoubleDrawBuffer.dispose();
    m_imgDoubleDrawBuffer=null;
    }
    }
      

  2.   

    不能单纯的做,有个兄弟说得对,用mvc架构
    具体实现应该比较简单
      

  3.   

    还得请教swt问题啊
    swt问题不熟啊
    只能up了