2012-02-10 102 views

回答

2

我已經找到了使用GC(canvas)類將任意控件(widget)渲染成圖像的方式。這裏是:

dragSource.addDragListener(new DragSourceListener() { 
    @Override 
    public void dragStart(DragSourceEvent dragSourceEvent) { 
     // getting control widget - Composite in this case 
     Composite composite = (Composite) ((DragSource) dragSourceEvent.getSource()).getControl(); 
     // Getting dimensions of this widget 
     Point compositeSize = composite.getSize(); 
     // creating new GC 
     GC gc = new GC(composite); 
     // Creating new Image 
     Image image = new Image(Display.getCurrent(),compositeSize.x,compositeSize.y); 
     // Rendering widget to image 
     gc.copyArea(image,0,0); 
     // Setting widget to DnD image 
     dragSourceEvent.image = image; 
    } 
... other overriden methods ... 
} 
+0

記得把你的資源放在'dragFinished'中。 :) – GGrec 2013-08-09 15:10:41

0

您可以使用一個未遵循鼠標位置的未修飾Shell,並在該Shell中包含要顯示的小部件。