Hi
guys :
Good
day !
I
have met a problem when developing UI with SWT, I created a Composite and add
Composites
to it as children ,each child Composite has an image as
data,my
logic to control the repaint is like this :
parentComposite.addPaintListener(new
PaintListener(){
public void paintControl(PaintEvent e)
{
System.out.println("Painting
...");
GC gc =
e.gc;
Rectangle bounds =
parentComposite.getBounds();
int halfHeight =
bounds.height >> 1;
int halfWidth =
bounds.width >> 1;
gc.drawLine(0, halfHeight,
bounds.width, halfHeight);
gc.drawLine(halfWidth, 0,
halfWidth,
bounds.height);
parentComposite.update();
Control[]
children = parentComposite.getChildren();
int
numChildren = children.length;
if(numChildren >
0){
System.out.println("Repaint composites in
slice editor :" + numChildren);
for(Control
child : children){
Composite composite =
(Composite)child;
System.out.println("drawing
child :" + child +" :" +
child.getData());
composite.setRedraw(true);
composite.redraw();
}
}
}
});
I created other composites
with parentComposite as parent,I added paintListener to child Composite like
this
Composite
composite = new
Composite(parentComposite,SWT.BORDER);
File imageFile = (File)imageButton.getData();
composite.setData(new
Image(display,imageFile.getAbsolutePath()));
composite.addPaintListener(new
PaintListener(){
public
void
paintControl(PaintEvent e) {
if(composite.getData()
!= null){
Image image = (Image)composite.getData();
GC gc = e.gc;
gc.drawImage(image, 0, 0);
}
}
});
but
the children’s paintControl method never gets called , I do not know why
,
can
anybody give me any clue ?
Best regards
!
Liang
chen