New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

Start a Discussion

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

How to set text color in a NSPopupButtonCell in an NSTableView

Post Reply New Thread Subscribe

Thread Tools

Member Since: Mar 19, 2009
Posts: 1
tmeehan is on a distinguished road

tmeehan is offline
This seems like it should be simple but for some reason I can not get it to work. I've tried a million different things with no success. All I want to do is set the color of the text in a NSPopUpButtonCell. One of my columns in an a subclass of NSTableView contains popup menus. Everything is working great so I move on to the last issue (I hope). I need to be able to set the color of the menu items based on certain criteria. But before I got to that I just tried to change the color from black to anything else. It just doesn't work. Below is the relevant code from my project. I don't usually post this much code but this is killing me and I was hoping someone might be able to spot something I am doing wrong and set me straight. Thanks in advance for any help. Basically, I just have subclasses of NSTableView, NSPopupButtonCell and NSTableColumn. I've stripped out all the junk not relevent to this problem.

********************* NSTableView Subclass ****************************

@interface ListBoxControl : NSTableView {
MyDataSource *TheDataSource;
myButtonCellClass *pcell;
- (void)awakeFromNib;
-(MyDataSource*) getDataSource;
-(myNSCell*) getCustomPCell;


@implementation ListBoxControl

- (void)awakeFromNib;
NSAttributedString *redString;
NSMenu *colorMenu;
NSMenuItem *theRedItem;
NSMutableDictionary *red_attrs;

TheDataSource = [[MyDataSource alloc] init];
[TheDataSource retain];
[TheDataSource initData];
[TheDataSource setHostView:self];
[self setDataSource:TheDataSource];

red_attrs = [NSMutableDictionary dictionaryWithCapacity:2];
[red_attrs setValue:[NSColor redColor] forKey:@"NSForegroundColorAttributeName"];
[red_attrs setValue:[NSColor redColor] forKey:@"NSStrokeColorAttributeName"];

redString = [[[NSAttributedString alloc] initWithString:@"Red" attributes:red_attrs] retain];

colorMenu = [[NSMenu alloc] initWithTitle:@"COLORMENU"];
theRedItem = [[NSMenuItem alloc] initWithTitle:@"Title1" action:NULL keyEquivalent:@""];
[theRedItem setAttributedTitle:redString];
[colorMenu addItem: theRedItem];

pcell = [[[myButtonCellClass alloc] initTextCell:@"" pullsDown:false] retain];
[pcell setEditable:NO];
[pcell setBordered:NO];
[pcell setMenu:colorMenu];


-(myNSCell*) getCustomPCell

return pcell;

-(MyDataSource*) getDataSource
return TheDataSource;

********************* NSPopUpButtonCell Subclass ****************************

@interface myButtonCellClass : NSPopUpButtonCell {



@implementation myButtonCellClass


********************* NSTableColumn Subclass ****************************
@interface customColumn : NSTableColumn {

- (id)dataCellForRow:(NSInteger)row;

@implementation customColumn
- (id)dataCellForRow:(NSInteger)row
return [[self tableView] getCustomPCell];

QUOTE Thanks

Post Reply New Thread Subscribe

« Problem - Functions looping for no reason | 'screen' command in unix »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Posting 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 Off
Forum Jump

Similar Threads
Thread Starter
Last Post
Text Fading In Effect?? mtnman2888 Web Design and Hosting 8 07-26-2008 06:07 PM
Applescript Help- Gmail Drive creation Willgecko OS X - Development and Darwin 0 01-22-2008 10:15 PM
text reflow problems from Quark 4.1 to Quark 6.5 plevault13 Running Windows (or anything else) on your Mac 2 09-30-2005 02:59 PM
text reflow problems from Quark 4.1 to Quark 6.5 plevault13 OS X - Apps and Games 0 09-30-2005 01:57 PM
how can i set the path? Bo Eddy OS X - Development and Darwin 1 05-12-2004 10:45 AM

All times are GMT -4. The time now is 10:10 AM.

Powered by vBulletin
Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.

Welcome to

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!

(4 digit year)

Already a member?