Java Utililty Methods JTree

List of utility methods to do JTree

Description

The list of methods to do JTree are organized into topic(s).

Method

StringgetExpansionState(JTree tree, int row)
get Expansion State
TreePath rowPath = tree.getPathForRow(row);
StringBuffer buf = new StringBuffer();
int rowCount = tree.getRowCount();
for (int i = row; i < rowCount; i++) {
    TreePath path = tree.getPathForRow(i);
    if (i == row || isDescendant(path, rowPath)) {
        if (tree.isExpanded(path))
            buf.append("," + String.valueOf(i - row));
...
JTreegetProjectTree()
get Project Tree
return mProjectTree;
ArrayListgetSelectionFromTree(JTree tree)
get Selection From Tree
ArrayList<String> list = new ArrayList<String>();
TreePath[] nodes = tree.getSelectionPaths();
for (int i = 0; i < nodes.length; i++) {
    TreePath temp = nodes[i];
    Object tempObj = temp.getLastPathComponent();
    DefaultMutableTreeNode treNode = (DefaultMutableTreeNode) tempObj;
    String device = String.valueOf(treNode.getUserObject());
    list.add(device);
...
intgetStopRow(JTree tree, int startRow)
get Stop Row
int startDepth = tree.getPathForRow(startRow).getPathCount();
int last = tree.getRowCount();
int stopRow = last;
for (int i = startRow + 1; i < last; ++i) {
    int depth = tree.getPathForRow(i).getPathCount();
    if (depth <= startDepth) {
        stopRow = i;
        break;
...
ImageIcongetTreeImage(String imageName)
get Tree Image
String imageFileName = PATHFORIMAGEFILES + imageName;
ImageIcon treeImageIcon = null;
try {
    Vector v = new Vector();
    InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream(imageFileName);
    if (is == null)
        is = ClassLoader.getSystemResourceAsStream(PATHFORIMAGEFILES + "unknown.gif");
    is = new BufferedInputStream(is);
...
TgetTreeObject(JTree tree, Class type)
Searches the given tree's selection path for a Node of the given type.
TreePath[] paths = tree.getSelectionPaths();
if (paths == null || paths.length == 0) {
    return null;
for (int i = 0; i < paths.length; i++) {
    TreePath path = paths[i];
    for (Object o : path.getPath()) {
        if (o.getClass().equals(type))
...
ColorgetTreeSelectionBorderColor()
get Tree Selection Border Color
return UIManager.getColor("Tree.selectionBorderColor");
booleanisPointOnTree(JTree tree, Point location)
Determines whether a point is on a row in a tree, or is outside the tree rows.
return (tree.getRowForLocation(location.x, location.y) != -1);
voidmaxDepth(JTree tree, int depth)
max Depth
collapse(tree, depth);
expand(tree, depth);
voidpaint(JTree tree)
Richiama il metodo paintImmediately() del JTree
Rectangle r = tree.getBounds();
int rowVisible = tree.getVisibleRowCount();
Rectangle rv = new Rectangle(r.width, r.height + rowVisible);
tree.paintImmediately(rv);