Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to get SWT stand-alone app to render UI in "dark mode"(SWT app UI "dark mode")
How to get SWT stand-alone app to render UI in "dark mode" [message #1852115] Fri, 29 April 2022 18:08 Go to next message
Eric Terrell is currently offline Eric TerrellFriend
Messages: 3
Registered: April 2022
Junior Member
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 #1852144 is a reply to message #1852115] Mon, 02 May 2022 13:52 Go to previous messageGo to next message
Andy Maleh is currently offline Andy MalehFriend
Messages: 75
Registered: March 2020
Location: Montreal, Quebec, Canada
Member
I blogged a while ago about SWT running in Dark Mode on the Mac when the OS switches to Dark Mode:
https://andymaleh.blogspot.com/2021/09/glimmer-dsl-for-swt-421-new-swtjdkjruby.html

That said, I don't currently have access to Windows to confirm Windows Dark Mode support, but if I get access, I would respond here about it though someone else might beat me to it.


EclipseCon / EclipseWorld / Agile Conference Speaker
Open-Source Software Author of Glimmer DSL for SWT
Re: How to get SWT stand-alone app to render UI in "dark mode" [message #1852171 is a reply to message #1852144] Tue, 03 May 2022 14:23 Go to previous messageGo to next message
Eric Terrell is currently offline Eric TerrellFriend
Messages: 3
Registered: April 2022
Junior Member
Thanks Andy.

I looked through your repo and didn't find any particular coding changes to accommodate "dark mode". Perhaps it "just worked" for you. If your code didn't use TreeViewers, you probably didn't experience the issue I'm fighting.

Sincerely,

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] Mon, 09 May 2022 00:37 Go to previous messageGo to next message
Andy Maleh is currently offline Andy MalehFriend
Messages: 75
Registered: March 2020
Location: Montreal, Quebec, Canada
Member
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:

https://i.imgur.com/Q26f3vG.png

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):

https://i.imgur.com/v4TqNPI.png

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:

https://i.imgur.com/bEBtrZS.png

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

https://i.imgur.com/Va197v9.png

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.


EclipseCon / EclipseWorld / Agile Conference Speaker
Open-Source Software Author of Glimmer DSL for SWT

[Updated on: Mon, 09 May 2022 00:57]

Report message to a moderator

Re: How to get SWT stand-alone app to render UI in "dark mode" [message #1852304 is a reply to message #1852287] Mon, 09 May 2022 22:21 Go to previous message
Eric Terrell is currently offline Eric TerrellFriend
Messages: 3
Registered: April 2022
Junior Member
Thanks for the details, Andy.
Previous Topic:Problem webkit2gtk SWT Browser Widget can not open URL to local html file
Next Topic:TabItems are not visible on mac if there is not enough space
Goto Forum:
  


Current Time: Mon May 06 16:09:02 GMT 2024

Powered by FUDForum. Page generated in 0.03465 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top