If you could keep a reference to the VerticalGroup
when you add it then you could simply call remove
on that Actor
to remove it from its parent.
If for some reason you can't get a reference to the node when it's either created or added to the Stage
Actor
tree then you can traverse the actors using some sort of path to find the one you want to delete.
For example; if you know that the "path" to the Actor
that you want to remove is always
VisTable/VisScrollPane/VisTable/VerticalGroup
then you can use a helper class like this one;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.utils.Array;
public class StageHand {
public static void removeByPath(Stage stage, Class...classes) {
removeByPath(stage, new Array<Class>(classes));
}
public static void removeByPath(Stage stage, Array<Class> classes) {
for(Actor actor : stage.getActors())
removeByPath(actor, 0, classes);
}
private static void removeByPath(Actor actor, int index, Array<Class> classes) {
Class<?> target = classes.get(index);
if (actor.getClass().equals(target))
{
if (index == classes.size - 1)
actor.remove();
else {
if (actor instanceof Group) {
for(Actor child : ((Group)actor).getChildren())
removeByPath(child, index + 1, classes);
}
}
}
}
}
And you'd call it something like this
StageHand.removeByPath(stage, VisTable.class, VisScrollPane.class, VisTable.class, VerticalGroup.class);
If you need to delete based on some other criteria (like Actor
's getName
method for instance), then that would be trivial to achieve as well.