Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get macOS Mojave Style Dark Mode in Java in a Swing Application?

I want to know if there is some way to get macOS Mojave style Dark Mode in a swing application in Java?

I want to get macOS Mojave Style Dark Mode on a JFrame in a Java Swing Application.

Please let me know.

Thanks

Asrar Bashir Sunge

like image 678
Asrar Sunge Avatar asked Mar 18 '19 08:03

Asrar Sunge


1 Answers

It seems the official solution to get dark mode is to use a system property. From JDK-8235363, this is available from JDK 14 and later:

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

To get the best user experience, you should probably always use the system value, to match the user's preferred setting:

-Dapple.awt.application.appearance=system

And of course test and make sure that you don't have your self-defined colors that makes text or components invisible or hard to see with this color scheme.


PS: If you are also looking for a Swing Look and Feel that matches the native macOS dark mode, have a look at VAqua. Disclaimer: I've never used it in a real application, but it looks extremely nice and uses native rendering to look just like the real thing.

like image 86
Harald K Avatar answered Oct 06 '22 00:10

Harald K