This example demonstrates the code needed to make a component draggable. The object being transferred in this example is a string.

    public class DraggableComponent extends JComponent
implements DragGestureListener, DragSourceListener {
DragSource dragSource; public DraggableComponent() {
dragSource = new DragSource();
dragSource.createDefaultDragGestureRecognizer(
this, DnDConstants.ACTION_COPY_OR_MOVE, this);
}
public void dragGestureRecognized(DragGestureEvent evt) {
Transferable t = new StringSelection("aString");
dragSource.startDrag (evt, DragSource.DefaultCopyDrop, t, this);
}
public void dragEnter(DragSourceDragEvent evt) {
// Called when the user is dragging this drag source and enters
// the drop target.
}
public void dragOver(DragSourceDragEvent evt) {
// Called when the user is dragging this drag source and moves
// over the drop target.
}
public void dragExit(DragSourceEvent evt) {
// Called when the user is dragging this drag source and leaves
// the drop target.
}
public void dropActionChanged(DragSourceDragEvent evt) {
// Called when the user changes the drag action between copy or move.
}
public void dragDropEnd(DragSourceDropEvent evt) {
// Called when the user finishes or cancels the drag operation.
}
}
Related Examples

最新文章

  1. MySQL,MariaDB:Undo | Redo [转]
  2. WPF 画心2.0版之元旦快乐
  3. NSOprationQueue 与 GCD 的区别与选用
  4. Windows程序设再读笔记00-序言
  5. 把页面上的图表导出为pdf文件,分享一种请求下载文件的方法
  6. SQL作业的操作全
  7. 深入理解ASP.NET的内部运行机制(转)
  8. Windows下安装破解JIRA6.3.6
  9. SQL Server DAC 管理员专用连接
  10. QTableWidget 用法总结(只能使用标准的数据模型,并且其单元格数据是QTableWidgetItem的对象)
  11. stata
  12. [Unity Asset]AssetBundle系列——游戏资源打包
  13. 微信小程序之----底部菜单action-sheet
  14. .Net Core MVC 过滤器(一)
  15. Pycon 2017: Python可视化库大全
  16. RPM基础知识
  17. JS小练习1
  18. 基本的socket编程的介绍
  19. 认识EasyUI——DataGrid的onClickRow事件
  20. Bootstrap3基础 caret 辅助类样式 下拉的小三角

热门文章

  1. mysql 查看是否被锁
  2. jquery资源
  3. Sampling and Estimation
  4. httpwebrequest异步参考
  5. 手机防盗之获取手机经纬度(Android)
  6. html 中 input 控制输入百分比数值范围(0.0-100)
  7. jquery+asp.net 调用百度geocoder手机浏览器定位--Api介绍及Html定位方法
  8. UBuntu14.04下安装和卸载Qt5.3.1
  9. webRTC开启摄像头
  10. 纯css3实现的3D按钮