DefaultMutableTreeNode (@NotNull DefaultMutableTreeNode root, String[] path) { DefaultMutableTreeNode result = root; outer: for (String step : path) { step = StringUtil.replace(step, "//", "/"); DefaultMutableTreeNode child = (result.getChildCount() == 0) ? null : (DefaultMutableTreeNode)result.getLastChild(); while (child != null) { if (step.equals(child.getUserObject())) { result = child; continue outer; } else child = child.getPreviousSibling(); } final DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(step); result.add(newNode); result = newNode; } return result; }