Skip to content

[Win11] Styling with SWT.Skin listener breaks look #1573

@tmssngr

Description

@tmssngr

Describe the bug
If I add a Skin listener and set the foreground color of a checkbox, it looks too compact.

To Reproduce
Run the following snippet on Windows 11 with 150% zoom level.

import java.io.*;

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

public class HiDpiTest {
	public static void main(String[] args) throws IOException {
		final Display display = new Display();
		display.addListener(SWT.Skin, event -> {
			if (event.widget instanceof Button button && (button.getStyle() & SWT.CHECK) != 0) {
				button.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
			}
		});

		final Shell shell = new Shell(display);
		shell.setLayout(new GridLayout(1, false));

		addCheckbox(shell);
		addCheckbox(shell).setSelection(true);
		addCheckbox(shell).setGrayed(true);

		final Button button = new Button(shell, SWT.PUSH);
		button.setText("Button");
		button.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));

		shell.setSize(shell.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		display.dispose();
	}

	private static Button addCheckbox(Composite parent) {
		final Button checkbox = new Button(parent, SWT.CHECK);
		checkbox.setText("Checkbox");
		checkbox.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false));
		return checkbox;
	}
}

The checkbox text is too close to the box:
2024-11-05 15_42_51-

With older SWT builds before commit 5dd0c28) it looks correctly:
2024-11-05 15_43_26-

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)
    Windows 11, 4k monitor, 150% zoom level

Version since
Eclipse or SWT version since when the behavior is seen [e.g. 4.23]

Workaround (or) Additional context
No known workaround.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions