Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;

public class Main {

    public TreePath getPath(TreeNode node) {
        List<TreeNode> list = new ArrayList<TreeNode>();

        while (node != null) {
            list.add(node);
            node = node.getParent();
        }
        Collections.reverse(list);

        return new TreePath(list.toArray());
    }
}