[英]How do i add JMenuBar to the Screen Menu Bar in macOS
I'm developing an app for macOS.我正在为 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.但是当我尝试将
JMenuBar
添加到JFrame
实例时,它只会添加JFrame
window 而不是 macOS 屏幕菜单栏。
I've tried Following this Article and it didn't work: https://www.formdev.com/flatlaf/macos/我试过关注这篇文章但没有用: https://www.formdev.com/flatlaf/macos/
What it did was just overlap the application title bar with the JMenuBar
.它所做的只是将应用程序标题栏与
JMenuBar
重叠。 I've read other articles online and still with no noticeable change.我在网上阅读了其他文章,但仍然没有明显的变化。
JRE Info: JRE信息:
% javac --version
javac 17.0.4.1
JDK Info: JDK信息:
% 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/ ).我是链接文章 ( https://www.formdev.com/flatlaf/macos/ ) 的作者。 This definitely works.
这绝对有效。
Make sure that you invoke following in your main()
method before creating UI:确保在创建 UI 之前在
main()
方法中调用以下内容:
System.setProperty( "apple.laf.useScreenMenuBar", "true" );
Make sure to use JFrame.setJMenuBar(JMenuBar)
to add the menu bar to the frame.确保使用
JFrame.setJMenuBar(JMenuBar)
将菜单栏添加到框架中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.