Java JTree maxDepth(JTree tree, int depth)

Here you can find the source of maxDepth(JTree tree, int depth)

Description

max Depth

License

Open Source License

Declaration

public static void maxDepth(JTree tree, int depth) 

Method Source Code


//package com.java2s;
/*//from  w  w  w  .  jav  a 2s.  c  o m
* Argus Open Source
* Software to apply Statistical Disclosure Control techniques
* 
* Copyright 2014 Statistics Netherlands
* 
* This program is free software; you can redistribute it and/or 
* modify it under the terms of the European Union Public Licence 
* (EUPL) version 1.1, as published by the European Commission.
* 
* You can find the text of the EUPL v1.1 on
* https://joinup.ec.europa.eu/software/page/eupl/licence-eupl
* 
* This software is distributed on an "AS IS" basis without 
* warranties or conditions of any kind, either express or implied.
*/

import javax.swing.JTree;

public class Main {
    public static void maxDepth(JTree tree, int depth) {
        collapse(tree, depth);
        expand(tree, depth);
    }

    /**
     * Collapse till a specified depth and also ensure that children of 
     * collapsed nodes are also collapsed.
     */
    public static void collapse(JTree tree, int depth) {
        for (int row = tree.getRowCount() - 1; row >= 0; row--) {
            if (tree.getPathForRow(row).getPathCount() >= depth + 1) {
                tree.collapseRow(row);
            }
        }
    }

    public static void expand(JTree tree, int depth) {
        for (int row = 0; row < tree.getRowCount(); row++) {
            if (tree.getPathForRow(row).getPathCount() < depth + 1) {
                tree.expandRow(row);
            }
        }
    }
}

Related

  1. getStopRow(JTree tree, int startRow)
  2. getTreeImage(String imageName)
  3. getTreeObject(JTree tree, Class type)
  4. getTreeSelectionBorderColor()
  5. isPointOnTree(JTree tree, Point location)
  6. paint(JTree tree)
  7. pickFirstIfNone(JTree tree)
  8. printComponentTree(final JComponent fc)
  9. RemoveAll(JTree tree)