void (StringBuilder sb, JTree tree, TreePath path) { boolean expanded = tree.isExpanded(path); boolean selected = tree.isPathSelected(path); sb.append(selected ? '[' : ' '); int count = path.getPathCount(); while (0 < count--) sb.append(" "); sb.append(expanded ? '+' : ' '); sb.append(path.getLastPathComponent()); if (selected) sb.append(']'); sb.append("\n"); }