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. Matlab图形调色

    Matlab图形调色 Simple example var colormap = require('colormap') options = {   colormap: 'jet',   // pic ...

  2. NodeJS操作Redis实现消息的发布与订阅

    首先先说一下流程: 1.保存数据到Redis,然后将member值publish到 chat频道(publish.js功能) 2.readRedis.js文件此前一直在监听chat频道,readRed ...

  3. Bash编程的test和条件语句

    1.if语句一句条件判断结果选择执行路径.最简单的if-then句型: if command //如果command的退出状态为0,执行body then body fi 重点:if认为command ...

  4. 恶意程序入侵 dbuspm-session 发现了新的方法制这种恶意程序

    直接从一台没服务器上把这两文件scp到当前的服务器上并替换这两个程序就ok了!!!!这种方法测试成功!!!! 出现了一个比效麻烦的事,服务器的负载正常,内存也正常,但就是很卡. 通过查找到线索:htt ...

  5. windows performance

    blogs.technet.com/b/perfguide/archive/2010/09/28/the-microsoft-pfe-performance-guide-start-here.aspx

  6. application , application pool., W3wp ,httpapplication, domain

    Hosting and Consuming WCF Services https://msdn.microsoft.com/en-us/library/bb332338.aspx http://www ...

  7. Build IKAnalyzer With Solr 5.1.0

    中文分詞裡IKAnalyzer和結巴是大家比較常用的分詞器, 不過IKAnalyzer已經很久沒有更新了, IKAnalyzer中文分词器V2012使用手册也跟IK Analyer 2012-FF H ...

  8. 转-webstorm快捷键

    默认配置-Eclipse的常用快捷键对照表 查找/代替 Webstorm快捷键 Eclipse快捷键 说明 ctrl+shift+N ctrl+shift+R 通过文件名快速查找工程内的文件(必记) ...

  9. Eclipse无法启动小结

    Eclipse启动的时候出现: The Eclipse executable launcher was unable to locate its companion shared library 针对 ...

  10. uC/OS-III 概要

    本章主要对 uC/OS-III 实时操作系统做一些概要介绍,使读者对 uC/OS-III 有个整体的浅 认识,为后面的章节的详细讲解做一个铺垫. 下图是 uC/OS-III 系统从底层到上层的文件结构 ...