发布于 2024-12-13 13:42:56 字数 288 浏览 1 评论 0原文

我在 Eclipse RCP 的视图中有一个 Nebula Grid (org.eclipse.nebula.widgets.grid.Grid) 控件。我想让该网格的行标题可见,以便在运行时显示行号,如下图所示:

在此处输入图像描述

现在,我的要求是我想在行标题列上显示文本/字符,就像其他列标题(例如全名、名称等)一样。我怎样才能在星云网格上实现这一目标?或者说,这个Nebula Grid控件不可以吗?我的替代方案是什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

椵侞 2024-12-20 13:42:56

我最终通过实现以下方法在nebulla Grid中实现了所需的功能:
public void Paint(GC paramGC, Object paramObject) {实现代码 }
内部接口:
setTopLeftRenderer(new IRenderer() { //接口方法}
如下:

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;
    }
});

其中,grdTable 是视图中正在使用的 Grid。

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.

柠北森屋 2024-12-20 13:42:56

更方便的方法是使用GridTableViewer:

        GridTableViewer grid = new GridTableViewer(parent, SWT.BORDER
            | SWT.V_SCROLL | SWT.H_SCROLL);
    grid.getGrid().setRowHeaderVisible(true);
    grid.setContentProvider(new ArrayContentProvider());
    grid.setRowHeaderLabelProvider(new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            cell.setText(cell.getElement().toString());
        }
    });

The more convenient way is to use GridTableViewer:

        GridTableViewer grid = new GridTableViewer(parent, SWT.BORDER
            | SWT.V_SCROLL | SWT.H_SCROLL);
    grid.getGrid().setRowHeaderVisible(true);
    grid.setContentProvider(new ArrayContentProvider());
    grid.setRowHeaderLabelProvider(new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            cell.setText(cell.getElement().toString());
        }
    });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文