Native menus on mac?

Is it possible to implement native OS X menus using JUCE?

I’ve not done this yet, but it’s on my to-do list!

Now it is done ! thanks a lot :slight_smile:

When using the OSX menuBar, the juce demo makes an assertion at shutdown when trying to remove the listener of the MenuBarModel :

void MenuBarModel::removeListener (MenuBarModelListener* const listenerToRemove) throw()
    // Trying to remove a listener that isn't on the list!
    // If this assertion happens because this object is a dangling pointer, make sure you've not
    // deleted this menu model while it's still being used by something (e.g. by a MenuBarComponent)
    jassert (listeners.contains (listenerToRemove));

    listeners.removeValue (listenerToRemove);

What’s the better way to avoid this assertion ?

When adding setMacMainMenu(0) in the destructor of ContentComp (inheriting from MenuBarModel) everything seems alright…

Yes - like it says, just make sure the model isn’t deleted before being removed. Calling setMacMainMenu(0) is the way to do it.

I just found this too. I had to add the setmenu(0) to my destructor.


Hi Jules,

Could I please make a request that if a Menu item is called “About…” or “Preferences” (or maybe this is indicated with some soft of menu item “hint flag” identifying it has a special meaning to the user/OS), and if the native Mac menu is being used, then those items are put under the left-hand Mac native menu bar item? On Mac apps, the About and Preferences items are always found there, with a separator too.

That would allow mac-native Juce app menus to behave just like normal Mac app menus… which would be cool!

Anyways, hoping that makes sense. :slight_smile:


Would love to do that, but couldn’t find any way of accessing that menu programatically. (I think there’s a thread about it somewhere…)

Just for reference… keeping it all in one place, as it were…:slight_smile: !

Anyways, HTH! The key thing might be that from MacOS 10.3, all menus are now implemented as HIViews; presumably this implies that it must be possible now to do what you want programmatically… :slight_smile:


My app repaints everytime a timer fires. However, if I open a native menu, the app stops repainting.

…yes, I think most mac apps will do the same - when you open the menus with MenuSelect, it goes into a modal loop that doesn’t let all the messages through. That function seems to be left-over from the old days of OS9, not sure if they’ve got a better way of doing it now.