If you just have to update the text of the Text2D, setString() should be enough.
If you have to create another Text2D, the solution I see is :
- Detach the Text2DBranchGroup. This branchgroup should have the capability BranchGroup.ALLOW_DETACH, Group.ALLOW_CHILDREN_EXTEND and Group.ALLOW_CHILDREN_WRITE and the parent node should have the capabilities Group.ALLOW_CHILDREN_EXTEND and Group.ALLOW_CHILDREN_WRITE.
- Remove the Text2D from the Text2DBranchGroup. No exception will be thrown I think because the Text2DBranchGroup is no longer alive.
- Create a new Text2D and add it to the Text2DBranchGroup.
- Attach the Text2DBranchGroup to his last parent.