Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSPanel with "Title Bar" unchecked in Interface Builder does not appear

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

like image 532
Craig Otis Avatar asked Oct 05 '11 02:10

Craig Otis


2 Answers

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.

like image 192
sudo rm -rf Avatar answered Sep 29 '22 13:09

sudo rm -rf


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.

http://cl.ly/3d0U3C0P3u2D0m3T1w1N

like image 44
James Boutcher Avatar answered Sep 29 '22 14:09

James Boutcher