Monday, July 8, 2013

Swt Tables setting the check box in cetre of the cell

tbleViewer.getTable().addListener(SWT.PaintItem, new Listener() {
 ......
.......

 int tmpWidth1 = 0;
                int tmpHeight1 = 0;
                int tmpX1 = 0;
                int tmpY1 = 0;
                tmpWidth1 = tbleViewer.getTable().getColumn(event.index).getWidth();
                tmpHeight1 = ((TableItem)event.item).getBounds().height;
       
                tmpX1 = tmpImage1.getBounds().width;
                tmpX1 = (tmpWidth1 / 2 - tmpX / 2);
                tmpY1 = tmpImage1.getBounds().height;
                tmpY1 = (tmpHeight1 / 2 - tmpY / 2);
                if(tmpX1 <= 0) tmpX1 = event.x;
                else tmpX1 += event1.x;
                if(tmpY1 <= 0) tmpY1 = event.y;
                else tmpY1 += event.y;
                event1.gc.drawImage(tmpImage1, tmpX1, tmpY1);

Courtsey : Read it somewhere on the internet and this stuff works .Full credit to the unknown author of this code ...