Skip to content

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

@Phillipus

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

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