Tree (TreeModel treeModel) { final Tree tree = new Tree(treeModel); tree.setRootVisible(false); tree.setShowsRootHandles(true); tree.setDragEnabled(false); tree.setEditable(false); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.setTransferHandler(new TransferHandler() { @Nullable @Override protected Transferable createTransferable(JComponent c) { final Object selection = tree.getLastSelectedPathComponent(); if (!(selection instanceof DefaultMutableTreeNode node)) { return null; } if (!(node.getUserObject() instanceof Configuration)) { return null; } return new TextTransferable(ConfigurationUtil.toXml((Configuration)node.getUserObject())); } @Override public int getSourceActions(JComponent c) { return COPY; } }); final TreeSpeedSearch speedSearch = TreeSpeedSearch.installOn( tree, false, treePath -> { final DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode)treePath.getLastPathComponent(); if (treeNode == myDraftTemplateNode) return SSRBundle.message("draft.template.node"); final Object userObject = treeNode.getUserObject(); return (userObject instanceof Configuration) ? ((Configuration)userObject).getName() : userObject.toString(); } ); tree.setCellRenderer(new ExistingTemplatesTreeCellRenderer(speedSearch, myDraftTemplateNode)); return tree; }