Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JMenuBar at the top in MacOSX

In the Java Desktop Application template used by Netbeans, a menu bar is created with JMenuBar and JMenuItems.

How can I get that bar displayed at the top, where menu bars are displayed in MacOSX instead of in-window, like in Windows?

like image 654
pupeno Avatar asked Nov 29 '22 19:11

pupeno


2 Answers

By adding something like this into your code:

if (System.getProperty("os.name").contains("Mac")) {
  System.setProperty("apple.laf.useScreenMenuBar", "true");
}
like image 195
oold Avatar answered Dec 02 '22 10:12

oold


I had the same issue, but I realized that the MenuBar needs to be added to the frame as:

frame.setJMenuBar(menuBar);

instead of: frame.add(jMenuBar); along with: System.setProperty("apple.laf.useScreenMenuBar", "true"); in the main method.

like image 42
zooes Avatar answered Dec 02 '22 08:12

zooes