Adding drag and drop support to Jtree

后端 未结 2 807
日久生厌
日久生厌 2021-01-20 04:26

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

i hav a created a custom DefaultMutableTreeNode subclass

hav a default TreeCellRenderer

w

相关标签:
2条回答
  • 2021-01-20 05:01

    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) 
    
    0 讨论(0)
  • 2021-01-20 05:11

    I found this also useful

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

    0 讨论(0)
提交回复
热议问题