Take the 2-minute tour ×

So I thought I had covered my bases, but apparently I'm missing a key step or two.

I have an NSPanel that is displayed (makeKeyAndOrderFront:) when an NSStatusItem is pressed. Things work great, but as the NSPanel displays a title bar, the panel is also draggable. (This is undesired.)

The first screenshot shows the panel with "Title Bar" enabled in Interface Builder, in the Appearance category. (Sorry for the blur, things are still under lock and key for now.)

First screenshot

The only change that is made in Interface Builder is unchecking the "Title Bar" checkbox. I then save and re-run, and that's what you see in the second screenshot. While a slight shadow appears, the panel does not.

enter image description here

Things I've tried:

  • I've subclassed the NSPanel and returned YES for canBecomeKeyWindow and canBecomeMainWindow after a bit of research, but (prior to subclassing) these methods both returned NO regardless of whether I was using a Title Bar or not. So I don't think this is the issue.

  • I've ensured that the frame for the NSPanel is properly set. It has a good height, and the origin is set properly as well.

Edit: Forgot to Mention:

The application is a menu-bar-only application. In the screenshot below, note that an additional entry was added to Info.plist to enforce this.

Info Plist

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

I've had problems with this in the past. I was able to resolve it by first "ignoring" other apps, then making it the key window. Give it a shot and see if it works for you.

[NSApp activateIgnoringOtherApps:YES];
[[self window]makeKeyAndOrderFront:self];

Also, try setting the window level to NSPopUpMenuWindowLevel during initialization.

[[self window]setLevel:NSPopUpMenuWindowLevel];

I have also had problems with the way that nib files are loaded on Mac OS X. They're loaded "lazily", which means that they won't be initialized until they're needed. This causes a problem when you're wanting to set specifics on the window, but you can't because awakeFromNib doesn't seem to be called, due to lazy nib loading. To fix this, here's what I've done in the past. In your delegate (or wherever you initialize your window), kick the window into action by accessing the window property on the initialized class:

wc = [[blah alloc]initWithWindowNibName:NSStringFromClass([blah class])];
(void)[wc window]; //just kicks the lazy nib loading into gear

By doing so, you're forcing the nib to initialize. That way, when the user clicks the menubar icon the nib is already initialized, and awakeFromNib has already been called.

share|improve this answer
Unfortunately, neither of those solutions seem to have helped. :( –  Craig Otis Oct 8 '11 at 20:37
You're sure? Where are you placing this? Did you try using them simultaneously? Also, I'll add something in my answer. –  sudo rm -rf Oct 8 '11 at 20:38
No, you know what, you're right. There was some other code that was interfering with those changes. Things are still a little wonky but I'm going to clear some of the code up and come back. –  Craig Otis Oct 8 '11 at 21:12
Perfect. The first set of code changes did the trick! –  Craig Otis Oct 8 '11 at 21:20
Awesome! Let me know if you have any more questions. ;) –  sudo rm -rf Oct 8 '11 at 21:21
add comment

While a slight shadow appears, the panel does not.

Are you saying makeKeyAndOrderFront: on this NSPanel object doesn't display it when running your app? I just created a sample project, NSButton triggers the same type of NSPanel to display, and it works fine.. titleBar enabled or not.


share|improve this answer
Agreed. It doesn't seem possible to reproduce this, there must be something else in the codebase that is causing this behaviour. –  jrturton Oct 8 '11 at 19:00
I may have left out a crucial piece of the puzzle. In the Info.plist file, the application must also be registered as an agent. (This is a menu-bar-only app, so no Dock icon is preferred.) Question updated with screenshot. –  Craig Otis Oct 8 '11 at 19:04
add comment

Your Answer


