I'm developing an app for macOS. But when i try to add the JMenuBar
to the JFrame
instance it just adds the the JFrame
window Instead of the macOS screen menu bar.
I've tried Following this Article and it didn't work: https://www.formdev.com/flatlaf/macos/
What it did was just overlap the application title bar with the JMenuBar
. I've read other articles online and still with no noticeable change.
JRE Info:
% javac --version
javac 17.0.4.1
JDK Info:
% java --version
java 17.0.4.1 2022-08-18 LTS
Java(TM) SE Runtime Environment (build 17.0.4.1+1-LTS-2)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.4.1+1-LTS-2, mixed mode, sharing)
I'm the author of the linked article ( https://www.formdev.com/flatlaf/macos/ ). This definitely works.
Make sure that you invoke following in your main()
method before creating UI:
System.setProperty( "apple.laf.useScreenMenuBar", "true" );
Make sure to use JFrame.setJMenuBar(JMenuBar)
to add the menu bar to the frame.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.