How to make a menu bar


#1

I am trying to make a menu bar but this all I have so far:

        MenuBarComponent mainMenuBar;

then in the constructor:

        addAndMakeVisible(mainMenuBar);

and when resized:

        mainMenuBar.setBounds(0, 0, getWidth(), 20);

That’s all. How can I add items to the menu? Can someone give me a simple example?


#2

You need to subclass MenuBarModel and override its pure virtual methods to set up your menu. Take a look at the MenusDemo class in the WidgetsDemo.cpp file of the JUCE Demo to see an example of how to do this.

Ed


#3

Just a question related to this theme : Is there a way to disable the top-level menu bar ?


#4

On OSX the best you can do is to use kiosk mode - there are methods in Desktop for doing that.


#5

Okay I managed to make the menubar and it is working. Now I would like to change the background/text/highlight colors of the menubar. Is it possible?


#6

No it’s not actually the solution that meets my requirements.
The issue I am refering to, is as follows :

  • The main window with a main menu bar and a main content component, is already shown on screen
  • I need to show temporarily a second content component on the same main window, until some selections will be done by the user .
  • I don’t want to show the second component via a new dialog or document window.
  • As long as the second content component is shown, no any other user activity, including menus, is acceptable.

However, top-level menu bar is still enabled and I could not find a way to disable it.

At this moment, I am deleting and re-creating the top-level menu, each time I encounter issues like this.


#7

Well, you’d need to just make your MenuBarModel remove or disable items when you don’t want them displayed.

If you use the ApplicationCommand stuff, it’ll disable things automatically based on the currently focused component, but if not then you can just roll your own menu disabling logic.