Here you can find the source of getLevel(TreeNode treeNode)
public static final int getLevel(TreeNode treeNode)
//package com.java2s; //License from project: Open Source License import javax.swing.tree.TreeNode; public class Main { public static final int getLevel(TreeNode treeNode) { int count = -1; TreeNode current = treeNode; do {// www.j a va 2 s .c o m current = current.getParent(); count++; } while (current != null); return count; } }