Bug 568160 - Control.setBackground() sometimes does not trigger recursive redraw
Summary: Control.setBackground() sometimes does not trigger recursive redraw
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.17   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-10-23 06:30 EDT by Stephan Aßmus CLA
Modified: 2020-10-23 06:30 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephan Aßmus CLA 2020-10-23 06:30:39 EDT
After upgrading the SWT version of our app, I have noticed that setting the background on a top-level Composite no longer triggers a redraw of all children reliably. In our applications there are several Composites side by side as the "top-level" panel. (Like "Views" in Eclipse). Only one of the views contains the focus control and the entire area is "darkened" by setting a darker background color on the top-level Composite. This color was reliably inherited by the entire view hierachy in each top-level view.

Since upgrading the SWT version from 4.9 to 4.17, the graphical update is no longer reliable. It works for one type of top-level view, but not for all the others. I could not determine what consitutes the difference of that view.

What I could validate is that the children in the view which works receive Paint events, in the others they do not. These views only update after some other event causes them to repaint, like for example when the top-level Composite is resized.

The work-around that I have found is to recursively call redraw() on all children, like this:

topLevelComposite.setBackground(newColor);
redrawRecursive(topLevelComposite.getChildren());

static void redrawRecursive(Control[] controls) {
    for (Control control : controls) {
        control.redraw();
        if (control instanceof Composite) {
            Composite composite = (Composite) control;
            redrawRecursive(composite.getChildren());
        }
    }
}