is TreePath Descendant - Java Swing

Java examples for Swing:JTree

Description

is TreePath Descendant

Demo Code


//package com.java2s;

import javax.swing.tree.TreePath;

public class Main {
    /**/*from  w  w  w  . ja  va  2  s  .  c om*/
     *
     *
     * @param path1
     * @param path2
     *
     * @return
     */
    public static boolean isDescendant(TreePath path1, TreePath path2) {
        int count1 = path1.getPathCount();
        int count2 = path2.getPathCount();

        if (count1 <= count2) {
            return false;
        }

        while (count1 != count2) {
            path1 = path1.getParentPath();

            count1--;
        }

        return path1.equals(path2);
    }
}

Related Tutorials