[go: up one dir, main page]

Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Nebula » change the background color of column headers in the Grid widget
change the background color of column headers in the Grid widget [message #1027449] Wed, 27 March 2013 01:17 Go to next message
Tony Hsiao is currently offline Tony HsiaoFriend
Messages: 13
Registered: March 2013
Junior Member
Hi, all, I'm using the Nebula Grid Widget and I want to change the background color of the column headers, how can I achieve this?

Thanks in advance!
Re: change the background color of column headers in the Grid widget [message #1057845 is a reply to message #1027449] Thu, 09 May 2013 09:44 Go to previous messageGo to next message
Kaushal Patankar is currently offline Kaushal PatankarFriend
Messages: 1
Registered: May 2013
Junior Member
Is there a solution for changing the background color of the headers?
I am also looking for similar behavior
Re: change the background color of column headers in the Grid widget [message #1059028 is a reply to message #1057845] Thu, 16 May 2013 09:54 Go to previous messageGo to next message
Tony Hsiao is currently offline Tony HsiaoFriend
Messages: 13
Registered: March 2013
Junior Member
No, I have not found it.
Re: change the background color of column headers in the Grid widget [message #1060050 is a reply to message #1059028] Wed, 22 May 2013 17:03 Go to previous messageGo to next message
Dhiresh Patel  is currently offline Dhiresh Patel Friend
Messages: 86
Registered: July 2009
Member
Write your own renderer - look at DefaultColumnHeaderRenderer
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 Go to previous message
Stefan Eidelloth is currently offline Stefan EidellothFriend
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);
		}
		
	}
Previous Topic:IntensityGraph, when the axis are updated?
Next Topic:[SOLVED] TableComboViewer Scrollbars?
Goto Forum:
  


Current Time: Sat Dec 14 04:31:57 GMT 2024

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

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

Back to the top