2

I have an EMF model, from which I generated UI form and embedded it into a wizard.

The check boxes appear with white background (see below) and it doesn't look nice.

Screenshot

How can I change the background color of the check box (avoid the white strip) ?

I tried to use BooleanControlSWTRenderer sub-class (see below), but it didn't work.

public class MyRenderer extends BooleanControlSWTRenderer {

    @Override
    protected Control createSWTControl(Composite parent, Setting setting) {


        final Button check = new Button(parent, SWT.CHECK);
        check.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_GRAY));
        check.setData(CUSTOM_VARIANT, "org_eclipse_emf_ecp_control_boolean"); //$NON-NLS-1$

        return check;

    }
}

Update 1 (05.11.2014 17:12 MSK): Calling check.setBackground(null) as suggested here also doesn't work.

Update 2 (05.11.2014 17:34 MSK): Modifying the code to this

@Override
protected Control createSWTControl(Composite parent, Setting setting) {
    Button check = new Button(parent, SWT.CHECK);

    check.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_GRAY));
    parent.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_GRAY));
    parent.setBackgroundMode(SWT.INHERIT_FORCE);

    check.setData(CUSTOM_VARIANT, "org_eclipse_emf_ecp_control_boolean"); //$NON-NLS-1$

    return check;

}

results in the following view.

Screenshot 2

2
  • setBackground rather than setForeground should work.
    – greg-449
    Nov 5, 2014 at 14:06
  • That was a typo. When I change it back to setBackground I get the same result. Nov 5, 2014 at 14:11

1 Answer 1

1
+100

This is probably what you need:

@SuppressWarnings("restriction")
public class MyRenderer extends BooleanControlSWTRenderer {

    @Override
    protected Control createSWTControl(final Composite parent, Setting setting) {
        final Button check = new Button(parent, SWT.CHECK);
        check.addPaintListener(new PaintListener() {
            @Override
            public void paintControl(PaintEvent arg0) {
                check.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_GRAY));
            }
        });
        return check;

    }
}

The difference to your MyRenderer is here we use an additinal workaround and add a paint listener due to this problem.

I tried it already and it works see this page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.