Example usage for javax.swing.tree TreeModel getIndexOfChild

List of usage examples for javax.swing.tree TreeModel getIndexOfChild

Introduction

In this page you can find the example usage for javax.swing.tree TreeModel getIndexOfChild.

Prototype

public int getIndexOfChild(Object parent, Object child);

Source Link

Document

Returns the index of child in parent.

Usage

From source file:Main.java

/**
 * Determines whether a path exists in a given tree model. For this to work,
 * the TreeModel.getIndexOfChild() method has to be correctly implemented
 *//*from ww w .j a  v a2s .co  m*/
public static boolean existsInModel(TreeModel model, TreePath path) {
    Object[] objects = path.getPath();
    if (!objects[0].equals(model.getRoot()))
        return false;
    Object prev = objects[0];
    for (int i = 1; i < objects.length; i++) {
        if (model.getIndexOfChild(prev, objects[i]) < 0)
            return false;
        prev = objects[i];
    }
    return true;
}