How to get SWT stand-alone app to render UI in "dark mode" [message #1852115] |
Fri, 29 April 2022 14:08  |
Eclipse User |
|
|
|
I've written a stand-alone app using the Eclipse SWT libraries:
https://github.com/EricTerrell/Vault3.Desktop
It was using the 4.18 versions of libraries (https://github.com/EricTerrell/Vault3.Desktop/blob/main/Java%20Vault/Vault/ant%20build%20scripts/ant_build_win64.xml)
I updated it to the 4.23 versions of the libraries, hoping that the UI would automatically render in dark mode when the OS was configured for dark mode (I tried this on Windows 10). The UI didn't change, all UI elements were still bright white.
I tried setting a "org.eclipse.swt.display.useSystemTheme" system property to "true", and again, I saw no change.
I searched around in Google and github for an answer, and thus far I haven't found anything that works.
What is the method for setting a stand-alone SWT app to render UI elements in dark mode, when the operating system is set for dark mode?
Thanks in advance,
Eric Bergman-Terrell
|
|
|
|
|
Re: How to get SWT stand-alone app to render UI in "dark mode" [message #1852287 is a reply to message #1852171] |
Sun, 08 May 2022 20:37   |
Eclipse User |
|
|
|
TreeViewer is not a widget. It is only the JFace MVC view model adapter (wrapper) for the Tree widget in SWT, so it does not affect the look of the widget directly either way yet the content and selection. All viewers extend org.eclipse.jface.viewers.Viewer, which are described in the Javadoc as "a model-based adapter on a widget."
In any case, automatic support for Dark Mode only started in SWT 4.21 as far as I know (although it might have existed without automatic support since 4.18), so you are right that it now works without any special "Dark Mode" code.
Here is my Hello, Tree! sample application running on the Mac (using SWT 4.23) in Light Mode:

I closed the app, switched my MacOS "Appearance" System Preferences to Dark Mode, and then restarted the app. I got the following look that demonstrates that Dark Mode does work in SWT with the Tree widget (automatically):

One thing to note is that I am using Glimmer DSL for SWT, which does NOT need TreeViewer or JFace because Glimmer offers its own Ruby-based alternative to JFace and JFace Data-Binding that is a lot simpler, terser, and more declarative (leveraging JRuby on the Java Virtual Machine). You can literally data-bind the entire tree with one line of code:
items <= [Employee, :ceo, tree_properties: {children: :subordinates, text: :to_s}]
That said, I did notice an issue when I tried to switch from Light Mode to Dark Mode WITHOUT restarting the app:

A similar issue occurs if I switch from Dark Mode to Light Mode WITHOUT restarting the app:

So, it seems that SWT's support for Dark Mode is not quite complete. For example, if I switch Light Mode to Dark Mode (or vice versa) with a non-SWT desktop app like Google Chrome WITHOUT restarting, it switches colors correctly without any problems.
SWT oughta support LIVE switching between Light Mode and Dark Mode eventually.
[Updated on: Sun, 08 May 2022 20:57] by Moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03616 seconds