Nebula GridViewerTable Column alignment. [message #1386529] |
Wed, 18 June 2014 02:46  |
Eclipse User |
|
|
|
Hi All,
I am using the Nebula GridViewerTable in my plugin.I am unable to align the image to the center of the column using the following code.Please help with this issue.
@Override
protected void measure(Event event, Object element) {
}
@Override
protected void paint(Event event, Object element) {
Image img = getImage(element);
if (img != null) {
Rectangle bounds = ((TableItem) event.item).getBounds(event.index);
Rectangle imgBounds = img.getBounds();
bounds.width /= 2;
bounds.width -= imgBounds.width / 2;
bounds.height /= 2;
bounds.height -= imgBounds.height / 2;
int x = bounds.width > 0 ? bounds.x + bounds.width : bounds.x;
int y = bounds.height > 0 ? bounds.y + bounds.height : bounds.y;
event.gc.drawImage(img, x, y);
}
}
Thanks,
Veeresh Hipparagi
|
|
|
|
Re: Nebula GridViewerTable Column alignment. [message #1386908 is a reply to message #1386907] |
Sun, 22 June 2014 21:20  |
Eclipse User |
|
|
|
The solution is to set a custom CellRenderer on the Column, like this
myImageColumn.setCellRenderer(new DefaultCellRenderer() {
@Override
public void paint(GC gc, Object value) {
GridItem item = (GridItem) value;
Image img = getMyImage(item.getData());
if (img != null) {
Rectangle bounds = getBounds();
Rectangle imgBounds = img.getBounds();
bounds.width /= 2;
bounds.width -= imgBounds.width / 2;
bounds.height /= 2;
bounds.height -= imgBounds.height / 2;
int x = bounds.width > 0 ? bounds.x + bounds.width : bounds.x;
int y = bounds.height > 0 ? bounds.y + bounds.height : bounds.y;
gc.drawImage(img, x, y);
}
}
});
|
|
|
Powered by
FUDForum. Page generated in 0.06476 seconds