拖拽控件java版
Button vv = new Button("vvvv");
DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(vv, DnDConstants.ACTION_MOVE, new DragGestureListener(){
public void dragGestureRecognized(DragGestureEvent ee) {
ee.startDrag(DragSource.DefaultMoveDrop,Toolkit.getDefaultToolkit().getSystemClipboard().getContents(this),new DragSourceListener(){
public void dragDropEnd(DragSourceDropEvent dragsourcedropevent) {
System.out.println("vvdragDropEnd");
}
public void dragEnter(DragSourceDragEvent dragsourcedragevent) {
System.out.println("vvdragEnter");
}
public void dragExit(DragSourceEvent dragsourceevent) {
System.out.println("vvdragExit");
}
public void dragOver(DragSourceDragEvent dragsourcedragevent) {
System.out.println("vvdragOver");
}
public void dropActionChanged(DragSourceDragEvent dragsourcedragevent) {
System.out.println("vvdropActionChanged");
}});
}});
///////////////////////////////////////////
Button b= new Button("bbbbb");
new DropTarget(b,new DropTargetListener(){
public void dragEnter(DropTargetDragEvent droptargetdragevent) {
System.out.println("bbdragEnter");
}
public void dragExit(DropTargetEvent droptargetevent) {
System.out.println("bbdragExit");
}
public void dragOver(DropTargetDragEvent droptargetdragevent) {
System.out.println("bbdragOver");
try {
System.out.println(droptargetdragevent.getTransferable().getTransferData(DataFlavor.stringFlavor));
} catch (Exception e) {
e.printStackTrace();
}
}
public void drop(DropTargetDropEvent droptargetdropevent) {
System.out.println("bbdrop");
}
public void dropActionChanged(DropTargetDragEvent droptargetdragevent) {
System.out.println("bbdropActionChanged");
}});
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。