我的问题:我在Eclipse RCP的视图中有一个nebulla Grid(org.eclipse.nebula.widgets.grid.Grid)控件。我可以通过以下代码使此网格的RowHeader可见: Grid grdTable = new Grid(compParent,SWT.BORDER | SWT.H_SCROLL); grdTable.setRowHeaderVisible(真); 这样,在运行时它会显示如下图所示的rownumbers:
现在,我的要求是我想在RowHeader列上显示text / char,就像其他列标题一样。全名,指定等。如何在nebulla网格上实现这一目标?或者,这个nebulla Grid控件不可能吗?可能是我的另类选择?
答案 0 :(得分:3)
我终于通过实现方法在nebulla Grid中实现了所需的功能: public void paint(GC paramGC,Object paramObject){implementaion code} 内部界面: setTopLeftRenderer(new IRenderer(){// interface methods} 如下:
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是视图中使用的网格。
答案 1 :(得分:1)
更方便的方法是使用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());
}
});