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

e640. 使一个组件可拖动的更多相关文章

  1. e641. 使一个组件成为拖放目标

    public class DropTargetComponent extends JComponent implements DropTargetListener { public DropTarge ...

  2. Android在代码中使用布局文件中的一个组件

    使用前必须要把组件与其父组件的关系断开,比如有一个组件的名称为scrollChildLayout,则可以使用下面的代码进行分离 ((ViewGroup)scrollChildLayout.getPar ...

  3. 使一个div始终显示在页面中间

    使一个div始终显示在页面中间 假设我们有一个div层:<div id=”myDiv”></div> 首先,我们用css来控制它在水平上始终居中,那么我们的css代码应该是这样 ...

  4. ITextSharp用来生成 PDF 的一个组件

    iTextSharp 是用来生成  PDF 的一个组件,在 1998 年夏天的时候,Bruno Lowagie ,iText 的创作者,参与了学校的一个项目,当时使用 HTML 来生成报告,但是,使用 ...

  5. QT UI 使一个QWidget里面的元素自动填充满本QWidget

    使一个QWidget里面的元素自动填充满本QWidget: 对象查看器,右键点击本QWidget,选择"布局",为此QWidget增加一个布局. 如果该QWidget只有一个对象, ...

  6. extjs每一个组件要设置唯一的ID

    extjs每一个组件要设置唯一的ID,否则会造成各种错误 EXTJS基本上是靠ID来识别组件的,假如你在panel1中有个ID:"keyword"的textfield,而panel ...

  7. 【JAVASCRIPT】React学习-如何构建一个组件

    摘要 react 学习包括几个部分: 文本渲染 JSX 语法 组件化思想 数据流 组件化思想 组件就是 UI + UI 交互逻辑,组件有三个常规map , 分别为state 状态 . props 数据 ...

  8. 微信小程序开发03-这是一个组件

    编写组件 基本结构 接上文:微信小程序开发02-小程序基本介绍 我们今天先来实现这个弹出层: 之前这个组件是一个容器类组件,弹出层可设置载入的html结构,然后再设置各种事件即可,这种组件有一个特点: ...

  9. Vue.js教程--基础(实例 模版语法template computed, watch v-if, v-show v-for, 一个组件的v-for.)

    官网:https://cn.vuejs.org/v2/guide/index.html Vue.js 的核心是一个允许采用简洁的模板语法来声明式地将数据渲染进 DOM 的系统. 视频教程:https: ...

随机推荐

  1. 从错误中学python(4)——最小公约数与辗转相除法

    题目 给你两个正整数a和b, 输出它们的最大公约数 辗转相除法 辗转相除法的步骤 def gcd(b,a): b,a=a,b%a if a==0: return b else: return gcd( ...

  2. usb端点(endpoint)知识详解

    stsw-stm32121库中: 把数据copy到对应端点的发送缓冲区后,使能发送状态编码STAT_TX=VALID,这时候usb的该端点就可以发送数据了 ----->即先调用usb_sil.c ...

  3. Spring Boot热部署(springloader)

    使用方式一 在pom.xml文件添加依赖包: <plugin> <groupId>org.springframework.boot</groupId> <ar ...

  4. python标准库介绍——23 UserString 模块详解

    ==UserString 模块== (2.0 新增) ``UserString`` 模块包含两个类, //UserString// 和 //MutableString// . 前者是对标准字符串类型的 ...

  5. linux centos7 常用命令【systemctl替换service】

    虽然linux的命令很多都是相同的,但是新版的centos 7 上面与以前的有些命令还是有所不同,不过还好,有提示.所以就在百度上面搜索了以下,作为记载,以后方便查看: centos7 上面启动服务以 ...

  6. Spring 一二事(9) - xml 形式的 AOP

    AOP在spring中是非常重要的一个 在切面类中,有5种通知类型: aop:before  前置通知 aop:after-returning  后置通知 aop:after  最终通知 aop:af ...

  7. Linux minilogd占用内存过高及开机启动项修改

    minilogd: 今天发现一台服务起的内存正常占用应该在70左右,但是内存占用却到了90%以上,用top查看发现minilogd占用了30%左右的内存,是不符合预期的,查看开机启动项并无minilo ...

  8. mongoose中的流查询stream query

    mongoose中的流查询stream query,功能类似于php中的mysql_fetch_array,每次从集合中获取一条记录(文档) var cursor = Person.find({ oc ...

  9. 设置PDF文件默认缩放比例

  10. android笔记一 控件属性

    <?xml version = "1.0" encoding = "utf-8"?> <LinearLayout xmlns:android= ...