Adding drag and drop support to Jtree

a 夏天 提交于 2019-12-02 00:39:12

问题


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

i hav a created a custom DefaultMutableTreeNode subclass

hav a default TreeCellRenderer

what all things do i need to add and where?


回答1:


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

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

You create a subclass of TransferHandler where you implement

canImport(JComponent comp, DataFlavor[] transferFlavors)

and

importData(JComponent comp, Transferable t) 



回答2:


I found this also useful

https://blogs.oracle.com/CoreJavaTechTips/entry/adding_drop_support_to_jtree



来源:https://stackoverflow.com/questions/1526291/adding-drag-and-drop-support-to-jtree

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!