如何在 Swing 应用程序中以 Java 获取 macOS Mojave 风格暗模式?
How to get macOS Mojave Style Dark Mode in Java in a Swing Application?
我想知道在 Java 中是否有某种方法可以在 swing 应用程序中获得 macOS Mojave 风格的黑暗模式?
我想在 Java Swing 应用程序中的 JFrame 上获得 macOS Mojave 风格暗模式。
请告诉我。
谢谢
阿斯拉尔·巴希尔·桑格
我想,您可以尝试使用 Darcula:
https://github.com/Revivius/nb-darcula
https://github.com/bulenkov/Darcula
import com.bulenkov.darcula.*;
...
...
BasicLookAndFeel darculaLookAndFeel = new DarculaLaf();
try {
UIManager.setLookAndFeel(darculaLookAndFeel);
} catch (UnsupportedLookAndFeelException ex) {
// ups!
}
要获得深色标题栏,请使用选项 -NSRequiresAquaSystemAppearance False
启动。例如:
java -jar myapp.jar -NSRequiresAquaSystemAppearance False
# ("false", "no" or "0" will also work)
注意:许多解决方案建议编辑 Info.plist
文件,但这些解决方案对我不起作用。
警告:一些框架can crash as a result of forcing this请谨慎使用。
看来官方的深色模式解决方案是使用系统属性。从 JDK-8235363 开始,这在 JDK 14 及更高版本中可用:
A new system property is added: "apple.awt.application.appearance"
to set the appearance of the whole java application.
- If no value is set then light mode will be used
- if
"system"
value is set then the current appearance of the macOS will be used
- Other possible values are
"NSAppearanceNameAqua"
(the same as light), or "NSAppearanceNameDarkAqua"
(requesting dark) See https://developer.apple.com/documentation/appkit/nsappearancenameaqua?language=objc
- If an incorrect value is set then light mode will be used
为了获得最佳用户体验,您可能应该始终使用 system
值,以匹配用户的首选设置:
-Dapple.awt.application.appearance=system
当然还要测试并确保您没有使用此配色方案使文本或组件不可见或难以看到的自定义颜色。
PS:如果您也在寻找与本机 macOS 深色模式匹配的 Swing 外观,请查看 VAqua。免责声明:我从未在真实的应用程序中使用过它,但它看起来非常漂亮并且使用本机渲染看起来就像真实的东西。
我想知道在 Java 中是否有某种方法可以在 swing 应用程序中获得 macOS Mojave 风格的黑暗模式?
我想在 Java Swing 应用程序中的 JFrame 上获得 macOS Mojave 风格暗模式。
请告诉我。
谢谢
阿斯拉尔·巴希尔·桑格
我想,您可以尝试使用 Darcula:
https://github.com/Revivius/nb-darcula
https://github.com/bulenkov/Darcula
import com.bulenkov.darcula.*;
...
...
BasicLookAndFeel darculaLookAndFeel = new DarculaLaf();
try {
UIManager.setLookAndFeel(darculaLookAndFeel);
} catch (UnsupportedLookAndFeelException ex) {
// ups!
}
要获得深色标题栏,请使用选项 -NSRequiresAquaSystemAppearance False
启动。例如:
java -jar myapp.jar -NSRequiresAquaSystemAppearance False
# ("false", "no" or "0" will also work)
注意:许多解决方案建议编辑 Info.plist
文件,但这些解决方案对我不起作用。
警告:一些框架can crash as a result of forcing this请谨慎使用。
看来官方的深色模式解决方案是使用系统属性。从 JDK-8235363 开始,这在 JDK 14 及更高版本中可用:
A new system property is added:
"apple.awt.application.appearance"
to set the appearance of the whole java application.
- If no value is set then light mode will be used
- if
"system"
value is set then the current appearance of the macOS will be used- Other possible values are
"NSAppearanceNameAqua"
(the same as light), or"NSAppearanceNameDarkAqua"
(requesting dark) See https://developer.apple.com/documentation/appkit/nsappearancenameaqua?language=objc- If an incorrect value is set then light mode will be used
为了获得最佳用户体验,您可能应该始终使用 system
值,以匹配用户的首选设置:
-Dapple.awt.application.appearance=system
当然还要测试并确保您没有使用此配色方案使文本或组件不可见或难以看到的自定义颜色。
PS:如果您也在寻找与本机 macOS 深色模式匹配的 Swing 外观,请查看 VAqua。免责声明:我从未在真实的应用程序中使用过它,但它看起来非常漂亮并且使用本机渲染看起来就像真实的东西。