Is there a way to detect whether Mac OS or Windows OS is in Dark Mode in Java

Ehsan Waheed :

Currently I am developing an application, However I am unaware of any methods to check if the system is in dark mode already.The application is made with JavaFX on a Mac. Currently I have a CheckMenuItem which when checked, loads up with the use of an IF statement a 'darkmode.css' file. And removes it if the file if the checkmenuitem box is unchecked.

However instead of a check MenuItem I want to be able to activate the css file when the OS is in darkmode and when its not for it to remove it again. I feel like that Java may not be able to do this. If there is any ways for this to be done I will be keen on learning and interested on how you may have implemented it.

In a nutshell native dark mode almost.

Stephen C :

There is no standard Java API for finding out whether the host's native UI is in "dark mode" or "night mode" .

In UI design terms, "dark mode" is a relatively new idea. From what I can tell, it only really took off as an idea in 2018; see https://en.wikipedia.org/wiki/Light-on-dark_color_scheme. This was well after both Swing and JavaFX had stabilized. (In the case of Swing, decades after!)

There is a recent (December 2019) RFE in the OpenJDK Bug tracker for detecting the host OS's dark mode setting: JDK-8235460

In the absence of standard Java APIs, you could try OS specific ideas; e.g. as described in the following:

For Android dark / night mode detection is supported:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=336691&siteId=1