Re: Setting image one pulldown popup button

Christiaan Hofman <[email protected]>
Newsgroups gmane.comp.macosx.devel
Message-ID <[email protected]>
On Mon, Dec 7, 2009 at 1:04 AM, Matt Neuburg <[email protected]> wrote:

> On or about 12/6/09 1:32 PM, thus spake "Christiaan Hofman"
> <[email protected]>:
>
> >
> > On Dec 6, 2009, at 21:16, Matt Neuburg wrote:
> >
> >> On or about 12/4/09 12:00 PM, thus spake "
> [email protected]"
> >> <[email protected]>:
> >>
> >>> Date: Fri, 4 Dec 2009 12:36:10 +0100
> >>> From: Christiaan Hofman <[email protected]>
> >>> Subject: Setting image one pulldown popup button
> >>>
> >>> After trying long and many times, I am unable to set the image on a
> pulldown
> >>> NSPopUpButton in code (it works in IB).
> >>>
> >>> I am aware that -setImage: does nothing. According to the docs, the
> image is
> >>> taken from the first menu item, so I set the image on the item at index
> 0. I
> >>> also played with other settings (in particular image position
> NSImageOnly
> >>> and
> >>> unbordered) but that has no effect. Also the order in which I set the
> image,
> >>> add the menu item, set pullsdown, etc does not seem to make any effect.
> >>> Neither does calling sycnhronizeTitleAndSelectedItem (though that
> should not
> >>> be relevant anyway). I never see the image.
> >>>
> >>> So does anyone know what I need to do to get the image in a popup?
> >>>
> >>
> >> Apple's MenuMadness example does not help here? Works okay on my
> machine...
> >> Perhaps I'm not understanding what the problem is. m.
> >>
> >
> > I'm using essentially the same code as the sample code and it does
> nothing for
> > me: I get an empty popup button.
>
> But what happens if you use *exactly* the same code as the sample code -
> namely, the sample code itself? On my machine, as I said, we see the image
> in the pulldown menu button. So your "essentially" differs in some way from
> "exactly", and the difference is crucial: whatever that difference is,
> that's what you're doing wrong. You don't show us any code, so it could be
> anything - you could be getting a nil image for all I know. But my point
> is,
> the fact that you have working sample code gives you a place to start
> figuring out what the mistake is. m.
>
> --
> matt neuburg, phd = [email protected], http://www.tidbits.com/matt/
> pantes anthropoi tou eidenai oregontai phusei
> Among the 2007 MacTech Top 25, http://tinyurl.com/2rh4pf
> AppleScript: the Definitive Guide, 2nd edition
> http://www.tidbits.com/matt/default.html#applescriptthings
> Take Control of Exploring & Customizing Snow Leopard
> http://tinyurl.com/kufyy8
> RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
> TidBITS, Mac news and reviews since 1990, http://www.tidbits.com
>
>
This is the code I use:

overflowButton = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(0, 0, 17,
10) pullsDown:YES];
[overflowButton setBordered:NO];
[[overflowButton cell] setArrowPosition:NSPopUpNoArrow];
[[overflowButton cell] setAltersStateOfSelectedItem:NO];
[[overflowButton cell] setBackgroundStyle:NSBackgroundStyleRaised];
[overflowButton addItemWithTitle:@""];
[[overflowButton itemAtIndex:0] setImage:[NSImage imageNamed:@"Overflow"]];

Though I've used several other variations without any change in behavior.

Christiaan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.