向Jtree添加拖放支持 [英] Adding drag and drop support to Jtree

查看:78
本文介绍了向Jtree添加拖放支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的JTree应用程序添加拖放支持

i want to add drag and drop support to my JTree application

我创建了一个自定义的DefaultMutableTreeNode子类

i hav a created a custom DefaultMutableTreeNode subclass

具有默认的TreeCellRenderer

hav a default TreeCellRenderer

我需要添加什么东西?在哪里?

what all things do i need to add and where?

推荐答案

最简单的方法是
1.调用tree.setDragEnabled(true)
2.设置tree.transferHandler

The easiest way is to
1. Call tree.setDragEnabled(true)
2. set tree.transferHandler

在以下位置有一个教程: http://java.sun.com/docs/books/tutorial /uiswing/dnd/intro.html

There's a tutorial at: http://java.sun.com/docs/books/tutorial/uiswing/dnd/intro.html

您创建要在其中实现的TransferHandler的子类

You create a subclass of TransferHandler where you implement

canImport(JComponent comp, DataFlavor[] transferFlavors)

importData(JComponent comp, Transferable t) 

这篇关于向Jtree添加拖放支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆