public static String getExpansionState(final JTree tree, final int row) {
    final TreePath rowPath = tree.getPathForRow(row);
    final StringBuffer buf = new StringBuffer();
    final int rowCount = tree.getRowCount();

    for (int i = row; i < rowCount; i++) {
      final TreePath path = tree.getPathForRow(i);
      if ((i == row) || isDescendant(path, rowPath)) {
        if (tree.isExpanded(path)) {
          buf.append(",");
          buf.append(String.valueOf(i - row));
        }
      } else {
        break;
      }
    }
    return buf.toString();
  }
Tests whether a tree contains a given node.

@param tree The tree to search.
@param node The node to search for.
@return True, if the node is part of the tree. False, otherwise.
java/zylib/src/main/java/com/google/security/zynamics/zylib/gui/jtree/TreeHelpers.java