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

2

7

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

Lauter answered 5/10, 2011 at 2:22 Comment(0)
B
4

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.

Bottrop answered 8/10, 2011 at 19:49 Comment(4)
Unfortunately, neither of those solutions seem to have helped. :(Lauter
You're sure? Where are you placing this? Did you try using them simultaneously? Also, I'll add something in my answer.Bottrop
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.Lauter
Awesome! Let me know if you have any more questions. ;)Bottrop
S
1

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

Skateboard answered 8/10, 2011 at 16:37 Comment(2)
Agreed. It doesn't seem possible to reproduce this, there must be something else in the codebase that is causing this behaviour.Frangos
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.Lauter

© 2022 - 2024 — McMap. All rights reserved.