Search code examples
grideclipse-rcp

can we set text on RowHeader Column in nebulla Grid in Eclipse RCP?


I have a Nebula Grid (org.eclipse.nebula.widgets.grid.Grid) control in my view in Eclipse RCP. I would to make the row header of this grid visible so that, at runtime it displays row numbers like following photo:

enter image description here

Now, my requirement is that I want to display a text/char on the row header column, like other column headers (e.g. Full Name, Designation, etc). How can I achieve this on the Nebula Grid? Or, is it not possible by this Nebula Grid control? What could be my alternative?


Solution

  • I finally achieved the required functionality in nebulla Grid by implementing the method : public void paint(GC paramGC, Object paramObject) {implementaion code } inside interface : setTopLeftRenderer(new IRenderer() { //interface methods} as follows :

    grdTable.setTopLeftRenderer(new IRenderer() {
        @Override
        public void setSize(int paramInt1, int paramInt2) {
        // TODO Auto-generated method stub  
        }
    
        @Override
        public void setSize(Point paramPoint) {
    
        // TODO Auto-generated method stub
    
        }           
        @Override
        public void setSelected(boolean paramBoolean) {
        // TODO Auto-generated method stub
        }
    
        @Override
        public void setMouseDown(boolean paramBoolean) {
        // TODO Auto-generated method stub      
        }
    
        @Override
        public void setLocation(int paramInt1, int paramInt2) {
        // TODO Auto-generated method stub              
        }
    
        @Override
        public void setLocation(Point paramPoint) {
        // TODO Auto-generated method stub                  
        }
    
        @Override
        public void setHover(boolean paramBoolean) {
        // TODO Auto-generated method stub              
        }
    
        @Override
        public void setFocus(boolean paramBoolean) {
        // TODO Auto-generated method stub              
        }
    
        @Override
        public void setExpanded(boolean paramBoolean) {
        // TODO Auto-generated method stub              
        }
    
        @Override
        public void setDisplay(Display paramDisplay) {
        // TODO Auto-generated method stub              
        }
    
        @Override
        public void setBounds(int paramInt1, int paramInt2, int paramInt3,
                        int paramInt4) {
        // TODO Auto-generated method stub                  
        }
    
        @Override
        public void setBounds(Rectangle paramRectangle) {
        // TODO Auto-generated method stub          
        }
    
        @Override
        public void paint(GC paramGC, Object paramObject) {
        // TODO Auto-generated method stub
        //paramGC.setAntialias(1);
        paramGC.setBackground(SWTResourceManager.getColor(240, 240, 240));
        Rectangle rect=new Rectangle(0, 0, 20, 2*(grdTable.getGroupHeaderHeight()));
            paramGC.fillRectangle(rect);
            //making foreground color of the Rectangle to be of text in ColumnHeaders   
        paramGC.setForeground(SWTResourceManager.getColor(0, 0, 0));
            //drawing appropriate text on the topLeftCorner of Grid
        paramGC.drawText("#",5,10,false);               
        }
    
        @Override
        public Point computeSize(GC paramGC, int paramInt1, int paramInt2,
                        Object paramObject) {
        // TODO Auto-generated method stub
    
        return null;
        }
    });
    

    Where, grdTable is the Grid being used in the view.