ArrayList<String> (final TreePath treePath, boolean includeSelf) { final ArrayList<String> result = new ArrayList<>(); int length = treePath.getPath().length - (includeSelf ? 0 : 1); for (int i = 0; i < length; i++) { Object o = ((DefaultMutableTreeNode)treePath.getPath()[i]).getUserObject(); if (o instanceof Group) { result.add(((Group)o).getName()); } } return result; }