Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Windows 11 dark colors mode
Windows 11 dark colors mode [message #1859361] Fri, 02 June 2023 10:17 Go to next message
Marco Maccaferri is currently offline Marco MaccaferriFriend
Messages: 147
Registered: July 2009
Senior Member
Hello,

I have an SWT application and would like to adapt it to dark modes.
With Linux (Ubuntu) seems to work as expected, but with Windows 11 doesn't seems to set the dark colors for the standard widgets.
The only thing I can tell is that Display.isSystemDarkTheme() returns true.
Is there a system property or something else I need to do ?

SWT version is 4.27.

Best regards,
Marco
Re: Windows 11 dark colors mode [message #1859624 is a reply to message #1859361] Tue, 20 June 2023 16:18 Go to previous messageGo to next message
Marco Maccaferri is currently offline Marco MaccaferriFriend
Messages: 147
Registered: July 2009
Senior Member
Well... more than 3000 reads without a single answer... wondering if I'm the only one writing applications with SWT...

Just for the records, after some experiments, I found that basically, on Windows, you have to do everything on your own. Either the OS or SWT (not sure which one) doesn't help you much. The only thing to do is to call OS.setTheme(true) to correctly pain all controls (otherwsie some things will be left light, like the menus and the scrollbars). Doesn't event seems possible to get a notification when the OS switches theme.

Linux seems more "smart" on this matter, providing default colors when the OS is set to dark (but still no notifcations as far as i know...).

OS.setTheme is an attempt to have an API for that, however since OS is well... OS-specific, the only way to use it in a multiplatform application is to use reflection, something like this:

            try {
                @SuppressWarnings("rawtypes")
                Class clazz = Class.forName("org.eclipse.swt.internal." + Platform.PLATFORM + ".OS");
                @SuppressWarnings("unchecked")
                Method method = clazz.getMethod("setTheme", boolean.class);
                method.invoke(null, true);
            } catch (Exception e) {
                e.printStackTrace();
            }


Unfortunately, seems that once you set it to true it can't be changed back (has no effect), this poses some limitations when switching from dark to light.

Any suggestion to make things working better is very welcome.
Re: Windows 11 dark colors mode [message #1860197 is a reply to message #1859624] Fri, 21 July 2023 12:54 Go to previous message
Tom Wheeler is currently offline Tom WheelerFriend
Messages: 17
Registered: June 2018
Junior Member
For our Eclipse RCP application, we were able to make progress by reading "SWT Changes" under the platform release notes for the releases in the interval 4.11 an upwards. Every now and then there are improvements to the Dark Theme support. One of the interesting ones was this: https://eclipse.dev/eclipse/news/4.16/platform_isv.php

It lead us to including the following in our application:
    /**
     * The string constants are defined in {@link Display}. It is our experience that these theme changes will require
     * application restart to display everything properly.
     */
    private void darkThemeAdjustments(String themeId) {
        Display display = getApplicationDisplay();
        if (ThemePreferenceConstants.PREFERENCE_SYMBOL_DARK_THEME.equals(themeId)) {
            display.setData("org.eclipse.swt.internal.win32.useDarkModeExplorerTheme", Boolean.TRUE);
            display.setData("org.eclipse.swt.internal.win32.useShellTitleColoring", Boolean.TRUE);
            display.setData("org.eclipse.swt.internal.win32.menuBarForegroundColor", new Color(display, 0xF9, 0xF9, 0xF9));
            display.setData("org.eclipse.swt.internal.win32.menuBarBackgroundColor", new Color(display, 0x38, 0x38, 0x38));
            display.setData("org.eclipse.swt.internal.win32.Combo.useDarkTheme", Boolean.TRUE);

            display.setData("org.eclipse.swt.internal.win32.all.use_WS_BORDER", Boolean.TRUE);
            display.setData("org.eclipse.swt.internal.win32.Canvas.use_WS_BORDER", Boolean.TRUE);
            display.setData("org.eclipse.swt.internal.win32.Label.use_WS_BORDER", Boolean.TRUE);
            display.setData("org.eclipse.swt.internal.win32.List.use_WS_BORDER", Boolean.TRUE);
            display.setData("org.eclipse.swt.internal.win32.Table.use_WS_BORDER", Boolean.TRUE);
            display.setData("org.eclipse.swt.internal.win32.Text.use_WS_BORDER", Boolean.TRUE);
        }
        else {
            // This has limited effect because we cannot get back to normal theme without restarting the application.
            display.setData("org.eclipse.swt.internal.win32.useDarkModeExplorerTheme", Boolean.FALSE);
            display.setData("org.eclipse.swt.internal.win32.menuBarForegroundColor",
                SWTResourceManager.getColor(SWT.COLOR_WIDGET_FOREGROUND));
            display.setData("org.eclipse.swt.internal.win32.menuBarBackgroundColor",
                SWTResourceManager.getColor(SWT.COLOR_WIDGET_BACKGROUND));
            display.setData("org.eclipse.swt.internal.win32.Combo.useDarkTheme", Boolean.FALSE);

            display.setData("org.eclipse.swt.internal.win32.all.use_WS_BORDER", Boolean.FALSE);
            display.setData("org.eclipse.swt.internal.win32.Canvas.use_WS_BORDER", Boolean.FALSE);
            display.setData("org.eclipse.swt.internal.win32.Label.use_WS_BORDER", Boolean.FALSE);
            display.setData("org.eclipse.swt.internal.win32.List.use_WS_BORDER", Boolean.FALSE);
            display.setData("org.eclipse.swt.internal.win32.Table.use_WS_BORDER", Boolean.FALSE);
            display.setData("org.eclipse.swt.internal.win32.Text.use_WS_BORDER", Boolean.FALSE);
        }
    }

Notice that (as far as we know) Eclipse RCP does not support fully switching color theme without restarting the application.

As of Eclipse-RCP-2022-12-R, there are still a few widgets that do not completely support Dark Theme on Windows-11. We have this experience with: Tree headings, Color Picker, Checkboxes and Radio Buttons.

Previous Topic:Edge Browser language is not changing
Next Topic:OLE Control in Java Application
Goto Forum:
  


Current Time: Mon May 06 12:23:36 GMT 2024

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

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

Back to the top