A JFrame
in (From Swing
) allows you to set a menu bar (Instance of MenuBar
using JFrame.setMenuBar(mb);
). This menu bar can appear in different locations depending on the system it's running on. If the operating system the appliation is running on has a menu bar on top of the screen, this menu bar set in the JFrame
usually appears in this menu bar. If this is not supported, the menu bar will be shown in the top of the frame itself.
You can see the different behaviours on different systems in the example bellow:
This is an example of the code I use to set up the menu bar:
// Initialize a menu bar
MenuBar mb = new MenuBar();
// Initialize the menu and some menu items, add these to the menu bar
Menu m = new Menu("Menu 1");
MenuItem mi1 = new MenuItem("Menu Item 1");
MenuItem mi2 = new MenuItem("Menu Item 2");
MenuItem mi3 = new MenuItem("Menu Item 3");
m.add(mi1);
m.add(mi2);
m.addSeparator();
m.add(mi3);
mb.add(m);
// Set the menu bar
setMenuBar(mb);
My question is: How do I check whether the menu bar will be shown in the frame itself or in the system's menu bar (if supported)? It would be great if there's any possible way to check this without initializing and defining a menu bar. Maybe this is impossible, if that is the case, is it possible to check for this same problem after a menu bar has been defined?