請問:如何使得JLabel支援drag?而JTextComponent類的元件僅需SetDragEnabled即可

zhanghongliang發表於2005-06-03
我寫了一個類繼承自JLabel,但實現DragSourceListener, DragGestureListener介面,可是測試時好像不能支援drag,急問原因????

class DraggableLabel extends JLabel
implements DragSourceListener, DragGestureListener {
public DraggableLabel(Icon image) {
super(image);
}

public DraggableLabel(String text) {
super(text);
dragSource = new DragSource();
dragSource.createDefaultDragGestureRecognizer(this,
DnDConstants.ACTION_COPY, this);
}

public void dragEnter(DragSourceDragEvent dsde) {
}

public void dragOver(DragSourceDragEvent dsde) {
}

public void dropActionChanged(DragSourceDragEvent dsde) {
}

public void dragExit(DragSourceEvent dse) {
}

public void dragDropEnd(DragSourceDropEvent dsde) {
}

/**
* a drag gesture has been initiated
*/
public void dragGestureRecognized(DragGestureEvent event) {
Transferable transfer = event.getTransferable();
dragSource.startDrag(event, DragSource.DefaultMoveDrop, transfer, this);
}

private DragSource dragSource = null;
}

相關文章