I understand to draw on a Composite, you can add a paint listener, but that results in drawing under the children. What if I want to draw over the top of children?
The following draws a line, but subc is drawn over it.
Composite c = new Composite(shell, 0);
c.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_BLUE));
c.setBounds(100, 100, 800, 600);
c.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
e.gc.drawLine(0, 0, 500, 1000);
}
});
final Composite subc = new Composite(c, 0);
subc.setLayout(null);
subc.setBounds(10, 10, 600, 400);
Unfortunately this is not an implemented feature, as you can see in Bug#114749.
You'd have to code your own custom solution (e.g, calculation the drawing area for each affected composite and then draw on each).
Its quite an old bug, but upvoting is always a good idea if you think this is a "must have".
It is not all that difficult to solve :-)
You need to add your
SWT.Paint
listener not just to theComposite
, but also to all the contained children (recursively). The trick is then to map the coordinates appropriately for each control...To illustrate, I have attached some code I use in a number of projects. And yes, I do know that there are missing classes, but you can probably get the idea from this.
and