I extended Howards Answer and used the JTree method convertValueToText to call the real cell renderer and save the results in a collection rather as one string.
TreeModel model = tree.getModel();
Collection<String> results = new LinkedList<>();
getTreeText(tree, model, model.getRoot(), result);
System.out.println(Arrays.toString(results.toArray()));
with recursive function getTreeText
private static void getTreeText(JTree tree, TreeModel model, Object object, Collection<String> result) {
result.add(tree.convertValueToText(object, true, true, true, 0, true));
for (int i = 0; i < model.getChildCount(object); i++) {
getTreeText(tree, model, model.getChild(object, i), result);
}
}
getTreeText
takes four arguments
tree
: Tree with tree nodes
model
: The model which we request for tree nodes
object
: The object we ask a string representation for (including all children)
result
: Collection to save each node String value
The method convertValueToText takes parameters not even used in base implementation. But depending on the object types used in the tree the renders might consume these values and the parameters could need fine tuning. In my case they where ignored at all.