Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>not sure I understand your setup: assuming you want the label to be a drop target, simply implement a custom Transferhandler which accepts the dataflavour as exported by the tree and do something with it</p> <p><strong>EDIT</strong></p> <p>To get hold of the TreePath use a custom Transferhandler on the tree as well: override its createTransferable which returns the TreePath:</p> <pre><code> final DataFlavor flavor =new DataFlavor(TreePath.class, "treePath"); TransferHandler treeHandler = new TransferHandler() { DataFlavor[] pathFlavour = new DataFlavor[] {flavor}; /** * @inherited &lt;p&gt; */ @Override protected Transferable createTransferable(JComponent c) { JTree tree = (JTree) c; final TreePath path = tree.getSelectionPath(); Transferable transferable = new Transferable() { @Override public DataFlavor[] getTransferDataFlavors() { return pathFlavour; } @Override public boolean isDataFlavorSupported(DataFlavor flavor) { return pathFlavour[0].equals(flavor); } @Override public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { return path; } }; return transferable; } public int getSourceActions(JComponent c) { return COPY; } }; tree.setTransferHandler(treeHandler); JLabel labelTarget = new JLabel("I'm a drop target!"); TransferHandler labelHandler = new TransferHandler() { /** * @inherited &lt;p&gt; */ @Override public boolean importData(JComponent comp, Transferable t) { try { LOG.info("import from: " + t.getTransferData(flavor)); } catch (Exception e) { e.printStackTrace(); } return true; } /** * @inherited &lt;p&gt; */ @Override public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) { return true; } }; labelTarget.setTransferHandler(labelHandler); </code></pre> <p>no need for an additional mouseListener</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload