get Component Tree Count - Java Swing

Java examples for Swing:JTree

Description

get Component Tree Count

Demo Code


//package com.java2s;

import java.awt.*;

public class Main {
    public static int getComponentTreeCount(Container c) {
        int cn = 1;
        for (Component node : c.getComponents()) {
            if (node instanceof Container) {
                cn += getComponentTreeCount((Container) node);
            } else {
                cn++;//from w w  w . ja  v  a2 s  . co m
            }
        }
        return cn;
    }
}

Related Tutorials