Java JTree Node expandPathsAfterChange(JTree tree, Hashtable state, DefaultMutableTreeNode root)

Here you can find the source of expandPathsAfterChange(JTree tree, Hashtable state, DefaultMutableTreeNode root)

Description

Call this after the structure of a JTree changes to re-expand the paths.

License

Open Source License

Parameter

Parameter Description
tree The tree
state The state. From initializeExpandedPathsBeforeChange
root The tree root

Declaration

public static void expandPathsAfterChange(JTree tree, Hashtable state, DefaultMutableTreeNode root) 

Method Source Code

//package com.java2s;
/*//  w w  w  .  ja  v  a 2  s.c  o m
 * Copyright 1997-2016 Unidata Program Center/University Corporation for
 * Atmospheric Research, P.O. Box 3000, Boulder, CO 80307,
 * support@unidata.ucar.edu.
 * 
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or (at
 * your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

import java.util.Hashtable;

import javax.swing.JTree;

import javax.swing.tree.DefaultMutableTreeNode;

import javax.swing.tree.TreePath;

public class Main {
    /**
     * Call this after the structure of a JTree changes to re-expand the paths.
     *
     * @param tree The tree
     * @param state The state. From initializeExpandedPathsBeforeChange
     * @param root The tree root
     */
    public static void expandPathsAfterChange(JTree tree, Hashtable state, DefaultMutableTreeNode root) {
        TreePath path = new TreePath(root.getPath());
        if (state.get(path.toString()) != null) {
            tree.expandPath(path);
        }
        for (int i = 0; i < root.getChildCount(); i++) {
            expandPathsAfterChange(tree, state, (DefaultMutableTreeNode) root.getChildAt(i));
        }
    }
}

Related

  1. createFolderNode(Object userObject)
  2. createSubTreeIfNecessary(TreeModel model, DefaultMutableTreeNode parent, String childName)
  3. expandAll(JTree tree, DefaultMutableTreeNode root)
  4. expandAll(JTree tree, DefaultMutableTreeNode treeNode)
  5. expandEntireTree(JTree tree, DefaultMutableTreeNode root, boolean expandRoot)
  6. expandTree(final JTree tree, final DefaultMutableTreeNode node)
  7. expandTreeRecurser(JTree tree, DefaultMutableTreeNode node)
  8. export(File file, DefaultMutableTreeNode node)
  9. findFirstTreeNodeMatchUserObject(DefaultMutableTreeNode treeNode, Object userObject)