Skip to main content



      Home
Home » Eclipse Projects » Nebula » Nebula GridViewerTable Column alignment.(How to align the image to the center of the Column)
Nebula GridViewerTable Column alignment. [message #1386529] Wed, 18 June 2014 02:46 Go to next message
Eclipse UserFriend
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 #1386907 is a reply to message #1386529] Sun, 22 June 2014 20:54 Go to previous messageGo to next message
Eclipse UserFriend
According to this forum post http://www.eclipse.org/forums/index.php/t/17892/, the OwnerDrawLabelProvider concept is not supported in the Nebula Grid.
Re: Nebula GridViewerTable Column alignment. [message #1386908 is a reply to message #1386907] Sun, 22 June 2014 21:20 Go to previous message
Eclipse UserFriend
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);
                }
            }
        });
Previous Topic:tool tip
Next Topic:Problems using CDateTimeCellEditor
Goto Forum:
  


Current Time: Wed Jun 18 05:13:53 EDT 2025

Powered by FUDForum. Page generated in 0.06476 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top