Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 06:46 Go to next message
veeresh hipparagi is currently offline veeresh hipparagiFriend
Messages: 2
Registered: June 2014
Junior Member
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] Mon, 23 June 2014 00:54 Go to previous messageGo to next message
Kaj Kandler is currently offline Kaj KandlerFriend
Messages: 36
Registered: July 2009
Location: Berlin, Germany
Member

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] Mon, 23 June 2014 01:20 Go to previous message
Kaj Kandler is currently offline Kaj KandlerFriend
Messages: 36
Registered: July 2009
Location: Berlin, Germany
Member

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: Thu Apr 25 05:12:14 GMT 2024

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

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

Back to the top