Java JTree Model redrawAllTreeCells(DefaultTreeModel treeModel)

Here you can find the source of redrawAllTreeCells(DefaultTreeModel treeModel)

Description

Repaints the cells for all the tree nodes in the tree represented by the given tree model.

License

BSD License

Parameter

Parameter Description
treeModel a parameter

Declaration

public static void redrawAllTreeCells(DefaultTreeModel treeModel) 

Method Source Code

//package com.java2s;
//License from project: BSD License 

import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeNode;

public class Main {
    /**// w  w  w. jav  a2s  . co m
    * Repaints the cells for all the tree nodes in the tree represented by the given tree model. This
    * is particularly useful when the renderer for a tree has changed leaving us open to the
    * possibility that the new renderer will leave the nodes' text cut off and an ellipsis at the
    * end. Note: The root node must be a TreeNode.
    * 
    * @param treeModel
    */
    public static void redrawAllTreeCells(DefaultTreeModel treeModel) {
        Object root = treeModel.getRoot();
        if (root instanceof TreeNode) {
            redrawAllTreeCellsRec(treeModel, (TreeNode) root);
        } else {
            System.err.println("Error: Tree root is not a TreeNode");
        }
    }

    private static void redrawAllTreeCellsRec(DefaultTreeModel treeModel, TreeNode parent) {
        treeModel.nodeChanged(parent);
        for (int i = 0; i < parent.getChildCount(); i++) {
            redrawAllTreeCellsRec(treeModel, parent.getChildAt(i));
        }
    }
}

Related

  1. getTreeIndents(TreeModel in)
  2. getTreeModelSize(TreeModel in)
  3. isTreePathInModel(TreeModel treeModel, TreePath treePath)
  4. logTreeNodes(TreeModel model, Object node, String indent)
  5. nodesChanged(DefaultTreeModel rightTreeModel)
  6. redrawAllTreeCellsRec(DefaultTreeModel treeModel, TreeNode parent)
  7. searchPath(TreeModel model, TreePath oldPath)
  8. setTreeObjects(TreeModel in, Object root, Object[] items, int index)
  9. setTreePaths(TreeModel in, Object root, TreePath[] items, Object[] path, int index)