Transferable (JComponent component) { if (component instanceof JTree tree) { TreePath[] selection = tree.getSelectionPaths(); if (selection != null && selection.length > 1) { return new TransferableList<>(selection) { @Override protected String toString(TreePath path) { return String.valueOf(path.getLastPathComponent()); } }; } } return null; }