expand JTree Path - Java Swing

Java examples for Swing:JTree

Description

expand JTree Path

Demo Code


//package com.java2s;

import javax.swing.JTree;

import javax.swing.tree.TreePath;

public class Main {
    /**/*from  w w w. j a va  2 s  .co  m*/
     * ?ffnet den Tree auch, wenn das letzte Element eines Pfads ein Blatt ist.
     *
     * @param tree Tree
     * @param path Pfad
     */
    public static void expandPath(JTree tree, TreePath path) {
        if (tree == null) {
            throw new NullPointerException("tree == null");
        }
        if (path == null) {
            throw new NullPointerException("path == null");
        }
        TreePath expandPath = path;
        if (tree.getModel().isLeaf(path.getLastPathComponent())) {
            expandPath = path.getParentPath();
        }
        tree.expandPath(expandPath);
    }
}

Related Tutorials