Re: adding menu item with image to main menu?
Re: adding menu item with image to main menu?
- Subject: Re: adding menu item with image to main menu?
- From: "Ujwal S. Sathyam" <email@hidden>
- Date: Sat, 04 Oct 2003 09:25:45 -0700
Thanks, I tried that, but it did not work. I then tried doing it AFTER I added the scriptMenuItem to the main menu. Then the correct title of the scriptMenuItem shows up as long as the title of the scriptMenuItem is not @"", i.e. it has some text in it. If I set it to @"", then the title of the submenu shows up. And in all cases, the image does not show up at all.
All this stuff works if I don't do this on the [NSApp mainMenu]. So either this is a bug, or the mainMenu does not support this, in which case it is not documented.
Ujwal
On 2003-10-03 21:49:42 -0700 Don Yacktman <email@hidden> wrote:
On Friday, October 3, 2003, at 01:08 PM, email@hidden wrote:
I would like to add an item to the main menu of my app and have it
represented
by an image, not text. I have tried using:
// get image
NSImage *scriptIcon = [NSImage imageNamed: @"script"];
[scriptIcon setScalesWhenResized: YES];
[scriptIcon setSize: NSMakeSize(16, 16)];
// create menu item with no title and set image
NSMenuItem *scriptMenuItem = [[NSMenuItem alloc] initWithTitle: @""
action:
nil keyEquivalent: @""];
[scriptMenuItem setImage: scriptIcon];
// create submenu
NSMenu *scriptMenu = [[NSMenu alloc] initWithTitle: @"Script"];
[scriptMenuItem setSubmenu: scriptMenu];
[scriptMenu release];
// add new menu item
[[NSApp mainMenu] addItem: scriptMenuItem];
[scriptMenuItem release];
However, this puts the name of the menu ("Script") into the main menu bar.
The
image is not displayed either.
Does anyone know how to add a menu item to the main menu represented by an
image? Is this supported? I don't want to use NSStatusItem since that will
be
put on the right side of the menu bar and will be visible even if my app is
not
the active app.
I've never tried this, so I don't know for sure if it will work, but try
setting the image and title of scriptMenuItem AFTER you call setSubMenu
instead of before. It just might work (though I can't guarantee it).
And even if that doesn't work, I'm sure there has to be a way to do it, even
if it isn't publically supported in Cocoa, because look at the way the
localization menu puts it's little flag up there... so keep looking! ;-)
--
Ujwal S. Sathyam
email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.