Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import javax.swing.tree.*;

public class Main {
    /**
     * Determines whether a path exists in a given tree model. For this to work,
     * the TreeModel.getIndexOfChild() method has to be correctly implemented
     */
    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;
    }
}