Skip to content

[Windows 11] MenuItem with style SWT.CHECK and image doesn't show state #501

Closed

Description

@Phillipus

Windows 11
Eclipse 4.26

Run this Snippet on Windows 10 and Window 11 and compare the drop down menu after selecting it:

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;

public class MenuImageTest {
    
	public static void main(String[] args) {
		final Display display = new Display();
		Shell shell = new Shell(display);
		shell.setText("Menu Image Test");
		
		Menu appMenuBar = display.getMenuBar();
		if(appMenuBar == null) {
			appMenuBar = new Menu(shell, SWT.BAR);
			shell.setMenuBar(appMenuBar);
		}
		
		MenuItem file = new MenuItem(appMenuBar, SWT.CASCADE);
		file.setText("File");
		
		Menu dropdown = new Menu(appMenuBar);
		file.setMenu(dropdown);
		
		MenuItem testMenu = new MenuItem(dropdown, SWT.CHECK);
		testMenu.setImage(new Image(display, MenuImageTest.class.getResourceAsStream("image.png")));
		testMenu.setText("Test Menu");
		
		shell.open();
		
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}
}

Use an image for image.png such as:

image

On Windows 10 selected state looks like this:

menu

In Windows 11 selected state looks like this:

menu 2

Activity

  1. SyntevoAlex commented on Dec 24, 2022

    @SyntevoAlex
    Member

    image

  2. SyntevoAlex commented on Dec 24, 2022

    @SyntevoAlex
    Member

    The screenshot above shows a difference between

    • SWT.CHECK menu with .setImage()
    • regular SWT.CHECK menu

    It seems that on Win11, theme decided to no longer paint blue square around the icon, hence the difference. I would say that the other problem here is that the image is always painted, whether checked or not.

  3. Phillipus commented on Dec 24, 2022

    @Phillipus
    ContributorAuthor

    I would say that the other problem here is that the image is always painted, whether checked or not.

    Isn't that the expected behaviour?

  4. SyntevoAlex commented on Dec 24, 2022

    @SyntevoAlex
    Member

    Looking at the default check mark (in regular SWT.CHECK menu without .setImage()) I would say that check image shall only appear when item is checked.

  5. SyntevoAlex commented on Dec 24, 2022

    @SyntevoAlex
    Member

    Studied the code more. It turns out that check and image are independent things. SWT even tries to manipulate MNS_CHECKORBMP style in attempt to save space when menu only has images and no checks.

    However, since XP theming, Windows seems to ignore that; it always paints check and image at the same spot.

    Here's a screenshot of a native snippet on Win7, using disable visual themes compatibility flag. On the left, flag is enabled (that is, XP theming disabled). On the right, flag is disabled (that is, XP theming enabled). The "up arrow" image is just a random image I grabbed.
    image

    It can be seen that same code, on same Windows, behaves differently based on XP theming.

  6. SyntevoAlex commented on Dec 24, 2022

    @SyntevoAlex
    Member

    For comparison, same native snippet on Win11. It can be seen that checked image item looks the same as non-checked image item. Just like in SWT.

    image

  7. SyntevoAlex commented on Dec 24, 2022

    @SyntevoAlex
    Member

    Conclusions: Windows theming issue, not an SWT bug.

  8. Phillipus commented on Jan 15, 2023

    @Phillipus
    ContributorAuthor

    Conclusions: Windows theming issue, not an SWT bug.

    If so, should we close this?

  9. SyntevoAlex commented on Jan 15, 2023

    @SyntevoAlex
    Member

    Probably.

  10. Phillipus commented on Jan 15, 2023

    @Phillipus
    ContributorAuthor

    Closing...

  11. BeckerWdf commented on Jun 21, 2023

    @BeckerWdf
    Member

    Conclusions: Windows theming issue, not an SWT bug.

    What does that mean? You mean it's a bug of Windows?

  12. 77 remaining items

  13. BeckerWdf commented on Oct 14, 2024

    @BeckerWdf
    Member

    I'd consider the option (C) the worst because the image is gone. Then one can question the images at all.

    I agree.

  14. BeckerWdf commented on Oct 14, 2024

    @BeckerWdf
    Member

    I we do a check mark, could the image be done as an overlay with alpha white blending around the checkbox so it's visible regards of the image under it? Perhaps with the checkbox in one of the corner?

    There might be a lot of icons that would look strange with that.

  15. merks commented on Oct 14, 2024

    @merks
    Contributor

    Yes, a checkbox overlay might well look not nice depending on the image. That being said, looking strange would be an improvement over the complete lack of state information. In any case, I want to make it clear that I'm highly appreciative of the effort being invested to address this issue.

  16. BeckerWdf commented on Oct 14, 2024

    @BeckerWdf
    Member

    n any case, I want to make it clear that I'm highly appreciative of the effort being invested to address this issue.

    Sure. Same here...

  17. wahlbrink commented on Oct 14, 2024

    @wahlbrink
    Contributor

    (E) Overlay Checkmark

    (E) overlay-checkmark

    When mixing with menu items without image:

    (B)
    (B) add-checkmark - s2

    (E)
    (E) overlay-checkmark - s2

  18. tmssngr commented on Oct 14, 2024

    @tmssngr
    Contributor

    I ask again: how other (native) applications handle this situation on Windows 11?

    Update: that's how they look in paint.net:
    Screenshot 2024-10-14 201212

    or LibreOffice (I don't have more native applications):
    Screenshot 2024-10-14 201657

  19. wahlbrink commented on Oct 14, 2024

    @wahlbrink
    Contributor

    Windows Explorer:
    windows-explorer

  20. lukeu commented on Nov 7, 2024

    @lukeu

    Just to reference another Eclipse feature impacted by this: Window Working Sets. (You may need to edit the Perspective to add this action group - then a button for it appears in the main toolbar.) It's particularly hard to use the "Java Main/Test Sets" actions, because these only show up in the drop-down menu but not the alternative dialog view. Once one has been clicked, it can be hard to understand the resulting behaviour. (For example, I run global file Searches based on my Window Working Set.)

    Great to see this is being worked on already!

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 OSbugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions