Home » Eclipse Projects » Nebula » change the background color of column headers in the Grid widget
| | | |
Re: change the background color of column headers in the Grid widget [message #1227792 is a reply to message #1060050] |
Sun, 05 January 2014 15:55 |
Stefan Eidelloth Messages: 29 Registered: September 2011 |
Junior Member |
|
|
Below is an example. Does anybody know, how I can set the color of the header region, right to the actual headers?
/**
* Renders the table headers
*/
class HeaderRenderer extends GridHeaderRenderer {
HeaderRenderer(){
//
}
@Override
public boolean notify(int event, Point point, Object value) {
// TODO Auto-generated method stub
return false;
}
@Override
public void paint(GC gc, Object value) {
Color backgroundColor = getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
Color foregroundColor = new Color(getDisplay(), 255,255,255);
Color selectionColor = new Color(getDisplay(), 153,204,255);
//get column
GridColumn column = (GridColumn)value;
//get selection state
boolean selected = this.isSelected();
//get coordinates
int x = getBounds().x;
int y = getBounds().y;
int width = getBounds().width;
int height = getBounds().height;
//set background color and draw rectangle
Color oldBackground = gc.getBackground();
Color oldForeground = gc.getForeground();
if (selected) {
gc.setBackground(selectionColor);
gc.setForeground(foregroundColor);
gc.fillGradientRectangle(x, y, width, height, true);
gc.setForeground(selectionColor);
gc.drawRectangle(x,y,width-1,height-1);
} else {
gc.setBackground(backgroundColor);
gc.setForeground(foregroundColor);
gc.fillGradientRectangle(x, y, width, height, true);
//gc.setForeground(oldForeground);
//gc.drawRectangle(x,y,width,height);
}
gc.setBackground(oldBackground);
gc.setForeground(oldForeground);
//draw text
String text = column.getText();
int textOffset = 3;
gc.drawString(text, x+textOffset, y+textOffset, true);
}
@Override
public Point computeSize(GC gc, int wHint, int hHint, Object value) {
//define text offset
int textOffset = 3;
//get text size
GridColumn column = (GridColumn)value;
String text = column.getText();
Point p = gc.stringExtent(text);
int width = p.x + 3*textOffset;
int height = p.y;
return new Point(width, height);
}
}
|
|
|
Goto Forum:
Current Time: Sat Dec 14 04:31:57 GMT 2024
Powered by FUDForum. Page generated in 0.03482 seconds
|