Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Changing the Color of a Column in NSTableView

Changing the Color of a Column in NSTableView
Thread Tools
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
Jul 12, 2003, 03:08 PM
 
Still cranking and learning how to use NSTableView and related classes. I'm a little bit stuck since I'm lacking some good examples on how to do some simple things. Here are the most inmediate needs:

1. How do I change the background color of each cell in a column? You can see this in spreadsheet apps; they have the first column grayed out and use it to indicate row number. I think I have to work with NSCell but how?

2. How do I change the fonts in an individual cell.

Thanks!
     
DaGuy  (op)
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
Jul 12, 2003, 05:29 PM
 
Well, here's what I got for the first item (changing the background color of cells). Too bad it doesn't work... How far am I?

Code:
NSTableColumn *firstColumn; firstColumn = [tableView tableColumnWithIdentifier:@"0"]; NSTextFieldCell *cell; cell = [[NSTextFieldCell alloc] init]; [cell setBackgroundColor:[NSColor lightGrayColor]]; [firstColumn setDataCell:cell];
     
DaGuy  (op)
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
Jul 12, 2003, 05:49 PM
 
Originally posted by DaGuy:
Well, here's what I got for the first item (changing the background color of cells). Too bad it doesn't work... How far am I?

Code:
NSTableColumn *firstColumn; firstColumn = [tableView tableColumnWithIdentifier:@"0"]; NSTextFieldCell *cell; cell = [[NSTextFieldCell alloc] init]; [cell setBackgroundColor:[NSColor lightGrayColor]]; [firstColumn setDataCell:cell];
Got it to work! I was missing the following:

Code:
[cell setDrawsBackground:YES];
Now, I need see how to workout the font deal; lets see how that goes.

     
DaGuy  (op)
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
Jul 12, 2003, 06:30 PM
 
Done! Below is the solution. Cocoa is so freaking cool!

Code:
NSTableColumn *firstColumn; firstColumn = [tableView tableColumnWithIdentifier:@"0"]; NSTextFieldCell *cell; cell = [[NSTextFieldCell alloc] init]; NSFont *indexFont; indexFont = [NSFont fontWithName:@"helvetica" size:10.0]; [cell setFont:indexFont]; [cell setDrawsBackground:YES]; [cell setBackgroundColor:[NSColor lightGrayColor]]; [cell setTextColor:[NSColor whiteColor]]; [firstColumn setDataCell:cell];
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:09 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2