Note that there are some explanatory texts on larger screens.

plurals
  1. PODragging node from JTree and dropping onto JLabel to perform an action
    primarykey
    data
    text
    <p>I want to implement DnD on my system by dragging a node from a JTree and dropping it onto a JLabel.</p> <p>The JLabel is an Icon with certain properties about a machine, and by dragging the information from the JTree node onto the JLabel I want it to be able to send a message to a client listening on that machine.</p> <p>Any help is much appreciated!</p> <p>Example of label method:</p> <pre><code>private void makeLabel(String html, final String version) { // Create a button to link to the DR environment //JButton button = new JButton(html); JLabel machineLabel = new JLabel(); machineLabel.setTransferHandler(new TransferHandler("text")); MouseListener listener = new DragMouseAdapter(); machineLabel.addMouseListener(listener); machineLabel.setIcon(onlineIcon); machineLabel.setToolTipText("IP: " + html); //Add the button to the panel and make sure it appears machineLabel.setSize(25, 10); vecIcons.addElement(machineLabel); buttonPanel.add(machineLabel); buttonPanel.setVisible(true); buttonPanel.validate(); dynaScrollPane.validate(); buttonPanel.repaint(); dynaScrollPane.repaint(); } </code></pre> <p>DragMouseAdapter method:</p> <pre><code> private class DragMouseAdapter extends MouseAdapter { public void mousePressed(MouseEvent e) { JComponent c = (JComponent) e.getSource(); TransferHandler handler = c.getTransferHandler(); handler.exportAsDrag(c, e, TransferHandler.LINK); } } </code></pre> <p>Then in order to make my tree draggable I just have: </p> <pre><code>exampleTree.setDragEnabled(true); </code></pre>
    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.
 

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