private static void expandNodeIfNotTooWide(Tree tree, PackageDependenciesNode node) { int count = node.getChildCount(); if (count > 5) return; // another level of nesting if (count == 1 && node.getChildAt(0).getChildCount() > 5) { return; } tree.expandPath(new TreePath(node.getPath())); }