Tree () { @NonNls final DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root"); final Tree tree = new Tree(root); tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { final TreePath selectionPath = tree.getSelectionPath(); if (selectionPath != null) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode)selectionPath.getLastPathComponent(); final Object userObject = node.getUserObject(); if (userObject instanceof AntTargetNodeDescriptor antBuildTarget) { mySelectedTarget = antBuildTarget.getAntTarget(); } else { mySelectedTarget = null; } } } }); tree.setCellRenderer(new MyTreeCellRenderer()); tree.setRootVisible(false); tree.setShowsRootHandles(true); TreeUtil.installActions(tree); TreeSpeedSearch.installOn(tree, false, path -> { final Object userObject = ((DefaultMutableTreeNode)path.getLastPathComponent()).getUserObject(); if (userObject instanceof AntTargetNodeDescriptor) { final AntBuildTarget target = ((AntTargetNodeDescriptor)userObject).getAntTarget(); return target.getDisplayName(); } return null; }); DefaultMutableTreeNode selectedNode = null; final AntConfiguration antConfiguration = AntConfigurationImpl.getInstance(myProject); for (AntBuildFile buildFile : antConfiguration.getBuildFileList()) { final DefaultMutableTreeNode buildFileNode = new DefaultMutableTreeNode(buildFile); DefaultMutableTreeNode selection = processFileTargets(antConfiguration.getMetaTargets(buildFile), buildFile, buildFileNode); if (selection != null){ selectedNode = selection; } selection = processFileTargets(antConfiguration.getModel(buildFile).getTargets(), buildFile, buildFileNode); if (selection != null){ selectedNode = selection; } root.add(buildFileNode); } TreeUtil.expandAll(tree); TreeUtil.selectInTree(selectedNode, true, tree); return tree; }