Community
Participate
Working Groups
It doesn't work so Eclipse has no menu bar. We put some code in place that we thought should work and it doesn't seem to do anything. It seems amazing to me that menu bars don't work in cocoa, given that cocoa is supposed to replace carbon. We must be doing something dumb.
Does this do the trick? application.setMainMenu(menuBar.nsMenu);
Does it do the trick for you? I believe we have commented out code in Display.setMenuBar() that already tried this.
I'm looking for a simple example to test this right now. My suggestion was not one of the choices commented out.
Found the file viewer example and it doesn't seem to work ... bummer
I debugged a bit further and found that inside Shell.setMenuBar() display.getActiveShell() == this returns false so the menu bar is never set on the display.
Comment out the test. Does your API work?
Sigh, no it doesn't. Did a little research and found this: http://lapcatsoftware.com/blog/2007/05/16/working-without-a-nib-part-1/ It seems there are problems running without a nib including setting the main menu. The article has some suggested hacks around the problem. Is standalone SWT required on OS X? Can we use a native launcher to properly initialize the menu bar, or is it time to read about hacking?
Let's see what Scott suggests.
Here's some more interesting info http://www.cocoabuilder.com/archive/message/cocoa/2007/11/4/192216
In the AWT we have a bare-bones nib installed in the Java VM framework. It has a basic menu bar with the application menu and a Window menu. Then, when an AWT app starts up, we have an application delegate class that overrides finishLaunching. Inside that we call [NSBundle loadNibFile:defaultNibFile externalNameTable: [NSDictionary dictionaryWithObject:self forKey:@"NSOwner"] withZone:nil]; That sets up the menu bar for the application. You really don't want to start down the road of using undocumented SPI, even though it's so easy to do in Objective-C. AFAIK, there are no non-nib-based ways to set the main menu in Cocoa, but I will ask -- things may have changed in the 4 years since we moved the AWT to Cocoa. You can get a simple nib by creating one in Interface Builder. Launch IB, then choose the MainMenu template. Delete all of the other menus except the one named NewApplication and save it. You could also make a copy of the one in /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Resources/English.lproj/DefaultApp.nib. (I'm technically on vacation this week for US Thanksgiving, so I may not read again until Monday.)
Pinging Scott: Did you have a chance to check with the Cocoa folks to see if there are any non-nib-based ways to set the main menu these days?
It's not possible to create a Cocoa application without a nib. Recent changes were made that will make it possible, but not on Leopard. Sorry! As soon as I get the go-ahead from our lawyers I will be able to do something here.
See bug #211359. Feel free to use the shared nib file in JavaVM.framework to set up the initial menu bar.
Created attachment 90448 [details] loading NIB method As Bug 211359 has been fixed with loading NIB method. I create this patch to set menu bar. In Display.setMenuBar(), it removes all items except application menu item, then add all items of Menu object to menu bar object. There is one thing I found that if the menu bar item has no sub menu, it can not be shown in menu bar. In this situation, I create an empty menu as the sub menu.
Carbon had a bug like this one, only it would crash. Need to check the carbon code to see what we did.
(In reply to comment #15) > In Display.setMenuBar(), it removes all items except application menu item, > then add all items of Menu object to menu bar object. There is one thing I > found that if the menu bar item has no sub menu, it can not be shown in menu > bar. In this situation, I create an empty menu as the sub menu. This is correct. In Cocoa the menu bar is treated like an NSMenu, and each of the top-level menus are NSMenuItems with a sub-menu corresponding to the NSMenu you want to add to the menu bar. It is an odd way to think about it, but it's all internally consistent and you don't have to introduce the separate notion of a menu bar like you had in Carbon.
Not so odd. Windows (win32) does it this way too.
Given the NextStep background of Cocoa that doesn't surprise me.
Thanks again Sky Yan. fixed > 20080225