Skip to content

[Win] Images in MenuItems are scaled incorrectly when autoscaling is disabled #2537

Closed

Description

@tmssngr

Describe the bug
With the release of SWT R4_37 the Windows zoom level causes (bitmap) images to be upscaled though swt.autoScale had been set to false.

To Reproduce

  • run this snippet on a Windows with a monitor scaling set to >100% (modify the path to a small image):
import java.io.*;
import java.nio.file.*;

import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

public class MenuItemImageTest {

	public static void main(String[] args) throws IOException {
		System.setProperty("swt.autoScale", "false");

		final Display display = new Display();
		try {
			final ImageData imageData;
			try (InputStream inputStream = Files.newInputStream(Paths.get("src/main/resources/images/smartgit/open-submodule-2.png"))) {
				imageData = new ImageData(inputStream);
			}
			final Image image = new Image(display, imageData);

			final Shell shell = new Shell(display);

			final Menu menu = new Menu(shell, SWT.POP_UP);
			shell.setMenu(menu);
			createMenuItem(SWT.PUSH, "Push", image, menu);
			createMenuItem(SWT.CHECK, "Unselected Check", image, menu);
			createMenuItem(SWT.CHECK, "Slected Check", image, menu).setSelection(true);

			shell.addListener(SWT.Paint, event -> event.gc.drawImage(image, 0, 0));
			shell.setSize(500, 400);
			shell.open();

			while (!shell.isDisposed()) {
				if (!display.readAndDispatch()) {
					display.sleep();
				}
			}
		}
		finally {
			display.dispose();
		}
	}

	private static MenuItem createMenuItem(int style, String text, Image image, Menu menu) {
		final MenuItem menuItem = new MenuItem(menu, style);
		menuItem.setText(text);
		menuItem.setImage(image);
		return menuItem;
	}
}
  • right-click to open a context menu

=> Results:

  1. the painted image is not scaled (correct)
  2. the image of the SWT.PUSH MenuItem is scaled incorrectly
  3. the image of the unchecked SWT.CHECK MenuItem is scaled incorrectly
  4. the image of the selected SWT.CHECK MenuItem is not scaled
  5. a checkmark is drawn onto the image of the SWT.CHECK MenuItem (incorrect)

2)-5) are regressions

Expected behavior

  • if swt.autoScale is set to true, scaling must not happen at all
  • no checkmark must be drawn onto an image (we solve it in our applications by using different images)

Screenshots
Windows 11 with 150% zoom.
Image

Environment:

  1. Select the platform(s) on which the behavior is seen:
    • All OS
    • Windows
    • Linux
    • macOS
  1. Additional OS info (e.g. OS version, Linux Desktop, etc)

  2. JRE/JDK version

Version since
R4_37, still reproducible with the latest master build.

Workaround (or) Additional context
Workaround: Use SWT R4_36.

Activity

  1. HeikoKlare commented on Sep 24, 2025

    @HeikoKlare
    Contributor

    Thank you for the report.

    • the image of the SWT.PUSH MenuItem is scaled incorrectly
    • the image of the unchecked SWT.CHECK MenuItem is scaled incorrectly
    • the image of the selected SWT.CHECK MenuItem is not scaled

    Seems like this was introduced with:

    We will have a look.

    • a checkmark is drawn onto the image of the SWT.CHECK MenuItem (incorrect)

    Why is that incorrect? https://eclipse.dev/eclipse/markdown/?f=news/4.37/platform.md#toggle-indicator-in-windows-11-menus

    Workaround (or) Additional context
    Workaround: Use SWT R4_36.

    Note that another workaround is of course to use auto-scaling.

  2. changed the title [-][Win] Images in MenuItems are scaled incorrectly (regression in R4_37)[/-] [+][Win] Images in MenuItems are scaled incorrectly when autoscaling is disabled[/+] on Sep 24, 2025
  3. tmssngr commented on Sep 24, 2025

    @tmssngr
    ContributorAuthor
    • a checkmark is drawn onto the image of the SWT.CHECK MenuItem (incorrect)

    Why is that incorrect? https://eclipse.dev/eclipse/markdown/?f=news/4.37/platform.md#toggle-indicator-in-windows-11-menus

    I consider it a regression because it changes the default behavior. However, setting the system property is a viable option for me.

    Workaround (or) Additional context
    Workaround: Use SWT R4_36.

    Note that another workaround is of course to use auto-scaling.

    Disabling the autoscaling on Windows is our workaround to fix asymmetric drawing - see #1596. The asymmetric drawing results would not be accepted by our customers.

  4. HeikoKlare commented on Sep 25, 2025

    @HeikoKlare
    Contributor

    I consider it a regression because it changes the default behavior. However, setting the system property is a viable option for me.

    Well, the regresison was that Windows 11 did not show any selection indicators anymore and that was the fix for it. If you call a fix for a bug a regression w.r.t. the broken state before then, yes, this is a regression. But I don't think that fits to the common definition it 🙂

    Disabling the autoscaling on Windows is our workaround to fix asymmetric drawing - see #1596. The asymmetric drawing results would not be accepted by our customers.

    Yes, I just wanted to mention that for everyone else who does actually not require disabled auto-scaling.
    We currently finalize the work an making controls non auto-scaled on-demand (we already use it for GEF diagrams). This is especially useful for pixel-perfect rendering where you don't want to have auto-scalingin place in general. That will then be the much better fit for you to only disable auto-scaling for the control(s) where you do custom painting and have everything else auto-scaled. It will render the swt.autoScale=false option quite obsolete as you could instead simply disable auto-scaling of the shell if you do not want to anything auto-scaled at all.

  5. tmssngr commented on Sep 25, 2025

    @tmssngr
    ContributorAuthor

    We currently finalize the work an making controls non auto-scaled on-demand (we already use it for GEF diagrams). This is
    especially useful for pixel-perfect rendering where you don't want to have auto-scalingin place in general.

    That sounds really interesting. I did not dare to ask for that, but I'm happy that other users have this demand, too.

  6. tmssngr commented on Sep 30, 2025

    @tmssngr
    ContributorAuthor

    @amartya4256 Could you please fix this regression (scaling though System.setProperty("swt.autoScale", "false") has been set)?

    Maybe adding this first line to MenuItem would fix it?

    private int adaptZoomForMenuItem(int currentZoom, Image image) {
    	currentZoom = DPIUtil.getZoomForAutoscaleProperty(currentZoom); // <--- fix?
    	int primaryMonitorZoomAtAppStartUp = getPrimaryMonitorZoomAtStartup();
  7. HeikoKlare commented on Sep 30, 2025

    @HeikoKlare
    Contributor

    We have an item in our backlog for this, but other items currently have higher priority. It will be fixed for the next release, but in particular for M1 there is more urgent stuff to do.

  8. HeikoKlare commented on Oct 17, 2025

    @HeikoKlare
    Contributor

    Note that the changed behavior also effects other auto-scale settings than just the disablement via false. E.g., just using default behavior (conforming to swt.autoScale=integer200) also changed behavior because menu items were, other than before, scaled according to the menu size instead of the autoscaled zoom value (i.e., either 100% or 200%). In consequence, when disabling monitor-specific UI scaling in Eclipse products, menu item images were differently scaled then before. This will be fixed with #2648.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    WindowsHappens on Windows OSregressionSomething that used to work

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions